Merge lp:~marcustomlinson/unity-scope-youtube/install_account_service into lp:unity-scope-youtube

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
Reviewer Review Type Date Requested Status
Pete Woods Pending
Review via email: mp+234264@code.launchpad.net

Commit message

Use new scopes::OnlineAccountClient class to get and monitor the youtube OA service

To post a comment you must log in.
Revision history for this message
Pete Woods (pete-woods) wrote :

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

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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-09-09 10:28:21 +0000
+++ CMakeLists.txt 2014-09-11 08:39:29 +0000
@@ -29,7 +29,7 @@
29 gio-unix-2.029 gio-unix-2.0
30 libaccounts-glib30 libaccounts-glib
31 libsignon-glib31 libsignon-glib
32 libunity-scopes>=0.6.032 libunity-scopes>=0.6.6
33 jsoncpp33 jsoncpp
34 net-cpp>=1.1.034 net-cpp>=1.1.0
35 process-cpp35 process-cpp
3636
=== modified file 'click/CMakeLists.txt'
--- click/CMakeLists.txt 2014-09-09 10:28:21 +0000
+++ click/CMakeLists.txt 2014-09-11 08:39:29 +0000
@@ -9,6 +9,9 @@
9 FILES9 FILES
10 "${CMAKE_CURRENT_BINARY_DIR}/manifest.json"10 "${CMAKE_CURRENT_BINARY_DIR}/manifest.json"
11 "apparmor.json"11 "apparmor.json"
12 "youtube.application"
13 "youtube.service"
14 "youtube.desktop"
12 DESTINATION ${CMAKE_INSTALL_PREFIX}15 DESTINATION ${CMAKE_INSTALL_PREFIX}
13)16)
1417
1518
=== modified file 'click/apparmor.json'
--- click/apparmor.json 2014-07-31 09:38:11 +0000
+++ click/apparmor.json 2014-09-11 08:39:29 +0000
@@ -1,6 +1,7 @@
1{1{
2 "template": "ubuntu-scope-network",2 "template": "ubuntu-scope-network",
3 "policy_groups": [3 "policy_groups": [
4 "accounts"
4 ],5 ],
5 "policy_version": 1.26 "policy_version": 1.2
6}7}
78
=== modified file 'click/manifest.json.in'
--- click/manifest.json.in 2014-09-09 12:48:43 +0000
+++ click/manifest.json.in 2014-09-11 08:39:29 +0000
@@ -5,12 +5,15 @@
5 "hooks": {5 "hooks": {
6 "youtube": {6 "youtube": {
7 "scope": "youtube",7 "scope": "youtube",
8 "apparmor": "apparmor.json"8 "apparmor": "apparmor.json",
9 "account-application": "youtube.application",
10 "account-service": "youtube.service",
11 "desktop": "youtube.desktop"
9 }12 }
10 },13 },
11 "icon": "icon",14 "icon": "youtube/icon.png",
12 "maintainer": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",15 "maintainer": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
13 "name": "@SCOPE_NAME@",16 "name": "@SCOPE_NAME@",
14 "title": "YouTube scope",17 "title": "YouTube scope",
15 "version": "1.0.11"18 "version": "1.0.12"
16}19}
1720
=== added file 'click/youtube.application'
--- click/youtube.application 1970-01-01 00:00:00 +0000
+++ click/youtube.application 2014-09-11 08:39:29 +0000
@@ -0,0 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<application id="com.ubuntu.scopes.youtube_youtube">
3 <description>YouTube</description>
4 <desktop-entry>com.ubuntu.scopes.youtube_youtube_1.0.12.desktop</desktop-entry>
5 <services>
6 <service id="com.ubuntu.scopes.youtube_youtube">
7 <description>Watch your favorite YouTube videos</description>
8 </service>
9 </services>
10</application>
011
=== added file 'click/youtube.desktop'
--- click/youtube.desktop 1970-01-01 00:00:00 +0000
+++ click/youtube.desktop 2014-09-11 08:39:29 +0000
@@ -0,0 +1,6 @@
1[Desktop Entry]
2Type=Application
3Name=YouTube
4Icon=youtube/icon.png
5OnlyShowIn=OnlineAccountsSettingsPage
6Exec=
07
=== renamed file 'data/accounts/services/youtube.service' => 'click/youtube.service'
--- data/accounts/services/youtube.service 2014-08-11 10:35:09 +0000
+++ click/youtube.service 2014-09-11 08:39:29 +0000
@@ -1,8 +1,28 @@
1<?xml version="1.0" encoding="UTF-8"?>1<?xml version="1.0" encoding="UTF-8"?>
2<service id="youtube">2<service id="com.ubuntu.scopes.youtube_youtube">
3 <type>sharing</type>3 <type>sharing</type>
4 <icon>youtube</icon>4 <icon>youtube</icon>
5 <name>Youtube</name>5 <name>YouTube</name>
6 <provider>youtube</provider>6 <provider>google</provider>
7 <translations>unity-scope-youtube</translations>7 <translations>unity-scope-youtube</translations>
8 <template>
9 <group name="auth">
10 <setting name="method">oauth2</setting>
11 <setting name="mechanism">web_server</setting>
12 <group name="oauth2">
13 <group name="web_server">
14 <setting name="Host">accounts.google.com</setting>
15
16 <setting name="AuthPath">o/oauth2/auth?access_type=offline</setting>
17 <setting name="TokenPath">o/oauth2/token</setting>
18 <setting name="RedirectUri">https://wiki.ubuntu.com/</setting>
19 <setting name="ResponseType">code</setting>
20 <setting type="as" name="Scope">['https://www.googleapis.com/auth/youtube.readonly']</setting>
21 <setting name="ClientId">368477111780-4tf0t65ol86nkvf6guksr8d1om0aebob.apps.googleusercontent.com</setting>
22 <setting name="ClientSecret">bNfrMJzYmesl2sm1XutVnlmv</setting>
23 <setting type="as" name="AllowedSchemes">['https','http']</setting>
24 </group>
25 </group>
26 </group>
27 </template>
8</service>28</service>
929
=== modified file 'data/CMakeLists.txt'
--- data/CMakeLists.txt 2014-07-22 10:12:43 +0000
+++ data/CMakeLists.txt 2014-09-11 08:39:29 +0000
@@ -18,4 +18,3 @@
18 DESTINATION18 DESTINATION
19 "${SCOPE_INSTALL_DIR}"19 "${SCOPE_INSTALL_DIR}"
20)20)
21
2221
=== removed directory 'data/accounts'
=== removed directory 'data/accounts/providers'
=== removed file 'data/accounts/providers/youtube.provider'
--- data/accounts/providers/youtube.provider 2014-08-11 10:35:09 +0000
+++ data/accounts/providers/youtube.provider 1970-01-01 00:00:00 +0000
@@ -1,30 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<provider id="youtube">
3 <name>Youtube</name>
4 <description>Connect your Youtube account</description>
5 <icon>youtube</icon>
6 <translations>unity-scope-youtube</translations>
7 <domains>.*google\.com</domains>
8 <plugin>generic-oauth</plugin>
9
10 <template>
11 <group name="auth">
12 <setting name="method">oauth2</setting>
13 <setting name="mechanism">web_server</setting>
14 <group name="oauth2">
15 <group name="web_server">
16 <setting name="Host">accounts.google.com</setting>
17
18 <setting name="AuthPath">o/oauth2/auth?access_type=offline</setting>
19 <setting name="TokenPath">o/oauth2/token</setting>
20 <setting name="RedirectUri">https://wiki.ubuntu.com/</setting>
21 <setting name="ResponseType">code</setting>
22 <setting type="as" name="Scope">['https://www.googleapis.com/auth/youtube.readonly']</setting>
23 <setting name="ClientId">368477111780-4tf0t65ol86nkvf6guksr8d1om0aebob.apps.googleusercontent.com</setting>
24 <setting name="ClientSecret">bNfrMJzYmesl2sm1XutVnlmv</setting>
25 <setting type="as" name="AllowedSchemes">['https','http']</setting>
26 </group>
27 </group>
28 </group>
29 </template>
30</provider>
310
=== removed directory 'data/accounts/qml-plugins'
=== removed directory 'data/accounts/qml-plugins/youtube'
=== removed file 'data/accounts/qml-plugins/youtube/Main.qml'
--- data/accounts/qml-plugins/youtube/Main.qml 2014-08-11 10:35:09 +0000
+++ data/accounts/qml-plugins/youtube/Main.qml 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1import Ubuntu.OnlineAccounts.Plugin 1.0
2
3OAuthMain {
4
5 // Override creationComponent so we can retreive that account's username
6 // This then appears in the accounts management page
7 creationComponent: OAuth {
8 function completeCreation(reply) {
9 console.log("Vimeo got reply: " + reply.AccessToken)
10 var http = new XMLHttpRequest()
11 var url = "https://api.vimeo.com/me";
12 http.open("GET", url, true);
13 http.setRequestHeader("Authorization", "Bearer " + reply.AccessToken)
14 http.setRequestHeader("Accept", "application/vnd.vimeo.*+json; version=3.0")
15 http.setRequestHeader("User-Agent", "unity-scope-vimeo 0.1; (http: //developer.vimeo.com/api/docs)")
16 http.onreadystatechange = function() {
17 if (http.readyState === 4) {
18 if (http.status == 200) {
19 console.log("ok")
20 var response = JSON.parse(http.responseText)
21 console.log("got name: " + response.name)
22 account.updateDisplayName(response.name)
23 account.synced.connect(finished)
24 account.sync()
25 } else {
26 console.log("error: " + http.responseText)
27 cancel()
28 }
29 }
30 };
31
32 http.send(null);
33 }
34 }
35}
360
=== removed directory 'data/accounts/services'
=== modified file 'debian/control'
--- debian/control 2014-09-09 10:28:21 +0000
+++ debian/control 2014-09-11 08:39:29 +0000
@@ -2,7 +2,7 @@
2Section: x112Section: x11
3Priority: optional3Priority: optional
4Build-Depends: cmake (>= 2.8.10),4Build-Depends: cmake (>= 2.8.10),
5Build-Depends: cmake-extras (>= 0.2),5 cmake-extras (>= 0.2),
6 debhelper (>= 9),6 debhelper (>= 9),
7 dh-translations,7 dh-translations,
8 g++-4.9,8 g++-4.9,
@@ -16,7 +16,7 @@
16 libnet-cpp-dev (>= 1.1.0),16 libnet-cpp-dev (>= 1.1.0),
17 libprocess-cpp-dev,17 libprocess-cpp-dev,
18 libsignon-glib-dev,18 libsignon-glib-dev,
19 libunity-scopes-dev (>= 0.6.0),19 libunity-scopes-dev (>= 0.6.6),
20 pkg-config,20 pkg-config,
21 python-tornado,21 python-tornado,
22Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>22Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
2323
=== removed file 'include/youtube/api/simple-oauth.h'
--- include/youtube/api/simple-oauth.h 2014-06-27 13:08:32 +0000
+++ include/youtube/api/simple-oauth.h 1970-01-01 00:00:00 +0000
@@ -1,88 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of version 3 of the GNU Lesser General Public License as published
6 * by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 * details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#ifndef VIMEO_API_SIMPLEOAUTH_H_
20#define VIMEO_API_SIMPLEOAUTH_H_
21
22#include <map>
23#include <memory>
24#include <string>
25
26#include <glib.h>
27#include <libaccounts-glib/accounts-glib.h>
28#include <libsignon-glib/signon-glib.h>
29
30namespace youtube {
31namespace api {
32
33class SimpleOAuth {
34public:
35 struct AuthData {
36 std::string client_id;
37 std::string client_secret;
38 std::string access_token;
39 };
40
41 SimpleOAuth(const std::string &service_name);
42
43 virtual ~SimpleOAuth() = default;
44
45 virtual SimpleOAuth::AuthData auth_data() const;
46
47protected:
48 void auth_login(const std::string &clientId, const std::string &clientSecret,
49 const std::string &accessToken);
50
51 static void login_cb(GObject *source, GAsyncResult *result,
52 void *user_data);
53
54 void login(SignonAuthSession *source, GAsyncResult *result);
55
56 void login_service();
57
58 void logout_service();
59
60 void lookup_account_service();
61
62 static void account_enabled_cb(AgManager *manager, guint account_id,
63 void *user_data);
64
65 void account_enabled(AgManager *manager, guint account_id);
66
67 gboolean setup_context();
68
69 static gboolean setup_context_cb(void *user_data);
70
71 std::string service_name_;
72
73 std::shared_ptr<GMainLoop> main_loop_;
74 std::shared_ptr<AgManager> manager_;
75 std::shared_ptr<AgAccountService> account_service_;
76 AgAuthData *ag_auth_data_;
77 std::shared_ptr<SignonAuthSession> session_;
78
79 std::shared_ptr<GVariant> auth_params_;
80 std::shared_ptr<GVariant> session_data_;
81
82 AuthData auth_data_;
83};
84
85}
86}
87
88#endif // VIMEO_API_SIMPLEOAUTH_H_
890
=== modified file 'include/youtube/scope/scope.h'
--- include/youtube/scope/scope.h 2014-08-01 15:26:57 +0000
+++ include/youtube/scope/scope.h 2014-09-11 08:39:29 +0000
@@ -20,13 +20,12 @@
20#define YOUTUBE_SCOPE_SCOPE_H_20#define YOUTUBE_SCOPE_SCOPE_H_
2121
22#include <youtube/api/config.h>22#include <youtube/api/config.h>
23#include <youtube/api/simple-oauth.h>
2423
24#include <unity/scopes/OnlineAccountClient.h>
25#include <unity/scopes/PreviewQueryBase.h>
26#include <unity/scopes/QueryBase.h>
27#include <unity/scopes/ReplyProxyFwd.h>
25#include <unity/scopes/ScopeBase.h>28#include <unity/scopes/ScopeBase.h>
26#include <unity/scopes/QueryBase.h>
27#include <unity/scopes/ReplyProxyFwd.h>
28#include <unity/scopes/QueryBase.h>
29#include <unity/scopes/PreviewQueryBase.h>
3029
31namespace youtube {30namespace youtube {
3231
@@ -34,8 +33,12 @@
3433
35class Scope: public unity::scopes::ScopeBase {34class Scope: public unity::scopes::ScopeBase {
36public:35public:
37 void start(std::string const&)36 Scope();
38 override;37
38 void service_update(unity::scopes::OnlineAccountClient::ServiceStatus const& status);
39 void update_config();
40
41 void start(std::string const&) override;
3942
40 void stop() override;43 void stop() override;
4144
@@ -48,6 +51,8 @@
4851
49protected:52protected:
50 youtube::api::Config::Ptr config_;53 youtube::api::Config::Ptr config_;
54 std::mutex config_mutex_;
55 unity::scopes::OnlineAccountClient oa_client_;
51};56};
5257
53}58}
5459
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-08-19 11:09:19 +0000
+++ src/CMakeLists.txt 2014-09-11 08:39:29 +0000
@@ -23,7 +23,6 @@
23 youtube/api/guide-category.cpp23 youtube/api/guide-category.cpp
24 youtube/api/playlist.cpp24 youtube/api/playlist.cpp
25 youtube/api/playlist-item.cpp25 youtube/api/playlist-item.cpp
26 youtube/api/simple-oauth.cpp
27 youtube/api/search-list-response.cpp26 youtube/api/search-list-response.cpp
28 youtube/api/video.cpp27 youtube/api/video.cpp
29 youtube/scope/preview.cpp28 youtube/scope/preview.cpp
3029
=== removed file 'src/youtube/api/simple-oauth.cpp'
--- src/youtube/api/simple-oauth.cpp 2014-06-27 13:08:32 +0000
+++ src/youtube/api/simple-oauth.cpp 1970-01-01 00:00:00 +0000
@@ -1,179 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of version 3 of the GNU Lesser General Public License as published
6 * by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 * details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <youtube/api/simple-oauth.h>
20
21#include <iostream>
22
23using namespace youtube::api;
24using namespace std;
25
26SimpleOAuth::SimpleOAuth(const std::string &service_name) :
27 service_name_(service_name) {
28 main_loop_.reset(g_main_loop_new(nullptr, true), g_main_loop_unref);
29
30 manager_.reset(ag_manager_new(), g_object_unref);
31 g_idle_add(setup_context_cb, this);
32
33 g_main_loop_run(main_loop_.get());
34}
35
36SimpleOAuth::AuthData SimpleOAuth::auth_data() const {
37 return auth_data_;
38}
39
40void SimpleOAuth::auth_login(const string &clientId, const string &clientSecret,
41 const string &accessToken) {
42 auth_data_.client_id = clientId;
43 auth_data_.client_secret = clientSecret;
44 auth_data_.access_token = accessToken;
45
46 g_main_loop_quit(main_loop_.get());
47}
48
49void SimpleOAuth::login_cb(GObject *source, GAsyncResult *result,
50 void *user_data) {
51 SignonAuthSession *session = (SignonAuthSession *) source;
52 SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data);
53 accounts->login(session, result);
54}
55
56void SimpleOAuth::login(SignonAuthSession *session, GAsyncResult *result) {
57 GError *error = nullptr;
58 session_data_.reset(
59 signon_auth_session_process_finish(session, result, &error),
60 g_variant_unref);
61
62 session_.reset();
63
64 if (error) {
65 cerr << "Authentication failed: " << error->message << endl;
66 g_error_free(error);
67 return;
68 }
69
70 char *tmp = nullptr;
71 string client_id;
72 string client_secret;
73 string access_token;
74 if (g_variant_lookup(auth_params_.get(), "ClientId", "&s", &tmp)) {
75 client_id = tmp;
76 }
77 if (g_variant_lookup(auth_params_.get(), "ClientSecret", "&s", &tmp)) {
78 client_secret = tmp;
79 }
80 if (g_variant_lookup(session_data_.get(), "AccessToken", "&s", &tmp)) {
81 access_token = tmp;
82 }
83
84 auth_login(client_id, client_secret, access_token);
85}
86
87void SimpleOAuth::login_service() {
88 ag_auth_data_ = ag_account_service_get_auth_data(account_service_.get());
89
90 GError *error = NULL;
91 session_.reset(
92 signon_auth_session_new(
93 ag_auth_data_get_credentials_id(ag_auth_data_),
94 ag_auth_data_get_method(ag_auth_data_), &error),
95 g_object_unref);
96 if (error != NULL) {
97 cerr << "Could not set up auth session: " << error->message << endl;
98 g_error_free(error);
99 return;
100 }
101
102 GVariantBuilder builder;
103 g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
104 g_variant_builder_add(&builder, "{sv}",
105 SIGNON_SESSION_DATA_UI_POLICY,
106 g_variant_new_int32(SIGNON_POLICY_NO_USER_INTERACTION));
107
108 auth_params_.reset(
109 g_variant_ref_sink(
110 ag_auth_data_get_login_parameters(ag_auth_data_,
111 g_variant_builder_end(&builder))), g_variant_unref);
112
113 signon_auth_session_process_async(session_.get(), auth_params_.get(),
114 ag_auth_data_get_mechanism(ag_auth_data_),
115 NULL, /* cancellable */
116 login_cb, this);
117}
118
119void SimpleOAuth::logout_service() {
120 session_data_.reset();
121 auth_params_.reset();
122 if (session_) {
123 signon_auth_session_cancel(session_.get());
124 session_.reset();
125 }
126 ag_auth_data_ = nullptr;
127 account_service_.reset();
128
129 auth_login(string(), string(), string());
130}
131
132void SimpleOAuth::lookup_account_service() {
133 GList *account_services = ag_manager_get_account_services(
134 manager_.get());
135 GList *tmp;
136 for (tmp = account_services; tmp != nullptr; tmp = tmp->next) {
137 AgAccountService *acct_svc = AG_ACCOUNT_SERVICE(tmp->data);
138 AgService *service = ag_account_service_get_service(acct_svc);
139 if (service_name_ == ag_service_get_name(service)) {
140 account_service_.reset(AG_ACCOUNT_SERVICE(g_object_ref(acct_svc)),
141 g_object_unref);
142 break;
143 }
144 }
145 ag_manager_list_free(account_services);
146
147 if (account_service_) {
148 login_service();
149 } else {
150 cerr << "Could not find account service" << endl;
151 g_main_loop_quit(main_loop_.get());
152 }
153}
154
155void SimpleOAuth::account_enabled_cb(AgManager *manager, guint account_id,
156 void *user_data) {
157 SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data);
158 accounts->account_enabled(manager, account_id);
159}
160
161void SimpleOAuth::account_enabled(AgManager *, guint) {
162 if (account_service_
163 && !ag_account_service_get_enabled(account_service_.get())) {
164 logout_service();
165 }
166 lookup_account_service();
167}
168
169gboolean SimpleOAuth::setup_context_cb(void *user_data) {
170 SimpleOAuth *accounts = static_cast<SimpleOAuth*>(user_data);
171 return accounts->setup_context();
172}
173
174gboolean SimpleOAuth::setup_context() {
175 lookup_account_service();
176 g_signal_connect(manager_.get(), "enabled-event",
177 G_CALLBACK(account_enabled_cb), this);
178 return FALSE;
179}
1800
=== modified file 'src/youtube/scope/query.cpp'
--- src/youtube/scope/query.cpp 2014-09-09 10:28:21 +0000
+++ src/youtube/scope/query.cpp 2014-09-11 08:39:29 +0000
@@ -28,6 +28,7 @@
28#include <unity/scopes/Annotation.h>28#include <unity/scopes/Annotation.h>
29#include <unity/scopes/CategorisedResult.h>29#include <unity/scopes/CategorisedResult.h>
30#include <unity/scopes/CategoryRenderer.h>30#include <unity/scopes/CategoryRenderer.h>
31#include <unity/scopes/OnlineAccountClient.h>
31#include <unity/scopes/QueryBase.h>32#include <unity/scopes/QueryBase.h>
32#include <unity/scopes/SearchReply.h>33#include <unity/scopes/SearchReply.h>
33#include <unity/scopes/SearchMetadata.h>34#include <unity/scopes/SearchMetadata.h>
@@ -295,7 +296,13 @@
295296
296 sc::CategorisedResult res(cat);297 sc::CategorisedResult res(cat);
297 res.set_title(_("Log-in to YouTube"));298 res.set_title(_("Log-in to YouTube"));
298 res.set_uri("settings:///system/online-accounts");299
300 sc::OnlineAccountClient oa_client("com.ubuntu.scopes.youtube_youtube", "sharing", "google");
301 oa_client.register_account_login_item(res,
302 query(),
303 sc::OnlineAccountClient::InvalidateResults,
304 sc::OnlineAccountClient::DoNothing);
305
299 reply->push(res);306 reply->push(res);
300}307}
301308
@@ -668,10 +675,9 @@
668 search(reply, query_string);675 search(reply, query_string);
669 }676 }
670677
671// FIXME Add this back when direct activation can be controlled678 if (!client_->config()->authenticated) {
672// if (!client_->config()->authenticated) {679 add_login_nag(reply);
673// add_login_nag(reply);680 }
674// }
675 } catch (domain_error &e) {681 } catch (domain_error &e) {
676 cerr << "ERROR: " << e.what() << endl;682 cerr << "ERROR: " << e.what() << endl;
677 }683 }
678684
=== modified file 'src/youtube/scope/scope.cpp'
--- src/youtube/scope/scope.cpp 2014-09-09 10:56:09 +0000
+++ src/youtube/scope/scope.cpp 2014-09-11 08:39:29 +0000
@@ -30,32 +30,56 @@
30using namespace youtube::scope;30using namespace youtube::scope;
31using namespace youtube::api;31using namespace youtube::api;
3232
33void Scope::start(string const&) {33Scope::Scope()
34 setlocale(LC_ALL, "");34 : oa_client_("com.ubuntu.scopes.youtube_youtube",
35 string translation_directory = ScopeBase::scope_directory() + "/../share/locale/";35 "sharing",
36 bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str());36 "google",
3737 sc::OnlineAccountClient::CreateInternalMainLoop)
38{
39 oa_client_.set_service_update_callback(std::bind(&Scope::service_update, this, std::placeholders::_1));
40}
41
42void Scope::service_update(sc::OnlineAccountClient::ServiceStatus const&)
43{
44 update_config();
45}
46
47void Scope::update_config()
48{
49 std::lock_guard<std::mutex> lock(config_mutex_);
38 config_ = make_shared<Config>();50 config_ = make_shared<Config>();
3951
40 if (getenv("YOUTUBE_SCOPE_APIROOT")) {52 if (getenv("YOUTUBE_SCOPE_APIROOT")) {
41 config_->apiroot = getenv("YOUTUBE_SCOPE_APIROOT");53 config_->apiroot = getenv("YOUTUBE_SCOPE_APIROOT");
42 }54 }
4355
44 SimpleOAuth oauth("youtube");
45 SimpleOAuth::AuthData auth_data;
46 if (getenv("YOUTUBE_SCOPE_IGNORE_ACCOUNTS") == nullptr) {56 if (getenv("YOUTUBE_SCOPE_IGNORE_ACCOUNTS") == nullptr) {
47 auth_data = oauth.auth_data();57 auto statuses = oa_client_.get_service_statuses();
58 for (auto const& status : statuses)
59 {
60 if (status.service_enabled)
61 {
62 config_->authenticated = true;
63 config_->access_token = status.access_token;
64 config_->client_id = status.client_id;
65 config_->client_secret = status.client_secret;
66 break;
67 }
68 }
48 }69 }
49 if (auth_data.access_token.empty()) {70
71 if (!config_->authenticated) {
50 cerr << "YouTube scope is unauthenticated" << endl;72 cerr << "YouTube scope is unauthenticated" << endl;
51 } else {73 } else {
52 cerr << "YouTube scope is authenticated" << endl;74 cerr << "YouTube scope is authenticated" << endl;
53 config_->authenticated = true;
54 }75 }
76}
5577
56 config_->access_token = auth_data.access_token;78void Scope::start(string const&) {
57 config_->client_id = auth_data.client_id;79 setlocale(LC_ALL, "");
58 config_->client_secret = auth_data.client_secret;80 string translation_directory = ScopeBase::scope_directory() + "/../share/locale/";
81 bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str());
82 update_config();
59}83}
6084
61void Scope::stop() {85void Scope::stop() {
@@ -63,12 +87,14 @@
6387
64sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query,88sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query,
65 const sc::SearchMetadata &metadata) {89 const sc::SearchMetadata &metadata) {
90 std::lock_guard<std::mutex> lock(config_mutex_);
66 auto client = make_shared<Client>(config_);91 auto client = make_shared<Client>(config_);
67 return sc::SearchQueryBase::UPtr(new Query(query, metadata, client));92 return sc::SearchQueryBase::UPtr(new Query(query, metadata, client));
68}93}
6994
70sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result,95sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result,
71 sc::ActionMetadata const& metadata) {96 sc::ActionMetadata const& metadata) {
97 std::lock_guard<std::mutex> lock(config_mutex_);
72 auto client = make_shared<Client>(config_);98 auto client = make_shared<Client>(config_);
73 return sc::PreviewQueryBase::UPtr(new Preview(result, metadata, client));99 return sc::PreviewQueryBase::UPtr(new Preview(result, metadata, client));
74}100}

Subscribers

People subscribed via source and target branches