Merge lp:~dbarth/ubuntu-system-settings-online-accounts/inline-plugin into lp:ubuntu-system-settings-online-accounts

Proposed by David Barth
Status: Superseded
Proposed branch: lp:~dbarth/ubuntu-system-settings-online-accounts/inline-plugin
Merge into: lp:ubuntu-system-settings-online-accounts
Diff against target: 2212 lines (+1631/-147)
37 files modified
.bzrignore (+1/-0)
debian/control (+0/-1)
src/browser-request.cpp (+5/-15)
src/module/OAuth.qml (+0/-1)
src/module/WebView.qml (+1/-2)
src/module/qmldir.in (+2/-0)
src/notification.cpp (+8/-0)
src/notification.h (+1/-0)
src/online-accounts-ui.pro (+2/-1)
src/qml/SignOnUiPage.qml (+40/-0)
src/signonui-request.cpp (+101/-46)
src/ui.qrc (+1/-0)
system-settings-plugin/AccountEditPage.qml (+66/-0)
system-settings-plugin/AccountItem.qml (+59/-0)
system-settings-plugin/AccountsPage.qml (+65/-0)
system-settings-plugin/AddAccountLabel.qml (+28/-0)
system-settings-plugin/AuthorizationPage.qml (+75/-0)
system-settings-plugin/EntryComponent.qml (+33/-0)
system-settings-plugin/MainPage.qml (+66/-0)
system-settings-plugin/NewAccountPage.qml (+38/-0)
system-settings-plugin/NoAccountsPage.qml (+54/-0)
system-settings-plugin/NormalStartupPage.qml (+46/-0)
system-settings-plugin/ProviderPluginList.qml (+42/-0)
system-settings-plugin/ProvidersList.qml (+62/-0)
system-settings-plugin/online-accounts.settings (+2/-1)
system-settings-plugin/plugin.cpp (+17/-70)
system-settings-plugin/plugin.h (+6/-9)
system-settings-plugin/system-settings-plugin.pro (+18/-0)
tests/online-accounts-ui/data/com.ubuntu.tests_application.application (+19/-0)
tests/online-accounts-ui/mock/notification-mock.cpp (+81/-0)
tests/online-accounts-ui/mock/notification-mock.h (+66/-0)
tests/online-accounts-ui/mock/request-mock.cpp (+136/-0)
tests/online-accounts-ui/mock/request-mock.h (+64/-0)
tests/online-accounts-ui/online-accounts-ui.pro (+2/-1)
tests/online-accounts-ui/tst_notification.cpp (+33/-0)
tests/online-accounts-ui/tst_signonui_request.cpp (+338/-0)
tests/online-accounts-ui/tst_signonui_request.pro (+53/-0)
To merge this branch: bzr merge lp:~dbarth/ubuntu-system-settings-online-accounts/inline-plugin
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Online Accounts Pending
Review via email: mp+230301@code.launchpad.net

This proposal has been superseded by a proposal from 2014-08-11.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
131. By David Barth

inline plugin take 2; made of bzr move'd qml files

132. By David Barth

only support OAuth providers for now

133. By David Barth

navigate back up once an account is removed

134. By David Barth

Simplify code by using Setup{} and Options{}

135. By David Barth

cleanups

136. By David Barth

no more plugin code

137. By David Barth

fix build in the rest of the project

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-06-05 13:28:30 +0000
+++ .bzrignore 2014-08-11 13:15:20 +0000
@@ -46,3 +46,4 @@
46/tests/online-accounts-ui/tst_inactivity_timer46/tests/online-accounts-ui/tst_inactivity_timer
47/tests/online-accounts-ui/tst_notification47/tests/online-accounts-ui/tst_notification
48/tests/online-accounts-ui/tst_service48/tests/online-accounts-ui/tst_service
49/tests/online-accounts-ui/tst_signonui_request
4950
=== modified file 'debian/control'
--- debian/control 2014-06-04 12:00:43 +0000
+++ debian/control 2014-08-11 13:15:20 +0000
@@ -36,7 +36,6 @@
36 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,36 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,
37 signon-ui-service,37 signon-ui-service,
38 ubuntu-system-settings38 ubuntu-system-settings
39Provides: signon-ui
40Description: Online Accounts setup for Ubuntu Touch39Description: Online Accounts setup for Ubuntu Touch
41 Online Accounts setup utility for the Ubuntu Touch System Settings.40 Online Accounts setup utility for the Ubuntu Touch System Settings.
4241
4342
=== modified file 'src/browser-request.cpp'
--- src/browser-request.cpp 2014-04-29 14:34:44 +0000
+++ src/browser-request.cpp 2014-08-11 13:15:20 +0000
@@ -28,6 +28,7 @@
2828
29#include <QDir>29#include <QDir>
30#include <QQmlContext>30#include <QQmlContext>
31#include <QQmlEngine>
31#include <QStandardPaths>32#include <QStandardPaths>
32#include <QTimer>33#include <QTimer>
33#include <SignOn/uisessiondata_priv.h>34#include <SignOn/uisessiondata_priv.h>
@@ -133,18 +134,9 @@
133 QObject::connect(m_dialog, SIGNAL(finished(int)),134 QObject::connect(m_dialog, SIGNAL(finished(int)),
134 this, SLOT(onFinished()));135 this, SLOT(onFinished()));
135136
136 QUrl webview("qrc:/MainWindow.qml");137 m_dialog->engine()->addImportPath(PLUGIN_PRIVATE_MODULE_DIR);
137 QDir qmlDir("/usr/share/signon-ui/qml");
138 if (qmlDir.exists())
139 {
140 QFileInfo qmlFile(qmlDir.absolutePath() + "/MainWindow.qml");
141 if (qmlFile.exists())
142 webview.setUrl(qmlFile.absoluteFilePath());
143 }
144
145 m_dialog->rootContext()->setContextProperty("request", this);138 m_dialog->rootContext()->setContextProperty("request", this);
146 m_dialog->rootContext()->setContextProperty("rootDir", m_rootDir);139 m_dialog->setSource(QUrl("qrc:/qml/SignOnUiPage.qml"));
147 m_dialog->setSource(webview);
148 } else {140 } else {
149 DEBUG() << "Setting request on handler";141 DEBUG() << "Setting request on handler";
150 q->handler()->setRequest(this);142 q->handler()->setRequest(this);
@@ -208,7 +200,7 @@
208200
209void BrowserRequestPrivate::onLoadFinished(bool ok)201void BrowserRequestPrivate::onLoadFinished(bool ok)
210{202{
211 Q_Q(const BrowserRequest);203 Q_Q(BrowserRequest);
212204
213 DEBUG() << "Load finished" << ok;205 DEBUG() << "Load finished" << ok;
214206
@@ -219,9 +211,7 @@
219211
220 if (m_dialog && !m_dialog->isVisible()) {212 if (m_dialog && !m_dialog->isVisible()) {
221 if (m_responseUrl.isEmpty()) {213 if (m_responseUrl.isEmpty()) {
222 Dialog::ShowMode mode =214 q->setWindow(m_dialog);
223 (q->windowId() == 0) ? Dialog::TopLevel : Dialog::Transient;
224 m_dialog->show(q->windowId(), mode);
225 } else {215 } else {
226 onFinished();216 onFinished();
227 }217 }
228218
=== modified file 'src/module/OAuth.qml'
--- src/module/OAuth.qml 2014-04-29 12:11:55 +0000
+++ src/module/OAuth.qml 2014-08-11 13:15:20 +0000
@@ -55,7 +55,6 @@
55 if (request) {55 if (request) {
56 console.log("RequestHandler captured request!")56 console.log("RequestHandler captured request!")
57 loader.setSource("WebView.qml", {57 loader.setSource("WebView.qml", {
58 "rootDir": request.rootDir,
59 "signonRequest": request58 "signonRequest": request
60 })59 })
61 } else {60 } else {
6261
=== modified file 'src/module/WebView.qml'
--- src/module/WebView.qml 2014-04-29 12:11:55 +0000
+++ src/module/WebView.qml 2014-08-11 13:15:20 +0000
@@ -5,7 +5,6 @@
55
6UbuntuWebView {6UbuntuWebView {
7 property QtObject signonRequest7 property QtObject signonRequest
8 property url rootDir
98
10 Component.onCompleted: url = signonRequest.startUrl9 Component.onCompleted: url = signonRequest.startUrl
1110
@@ -22,6 +21,6 @@
22 onUrlChanged: signonRequest.currentUrl = url21 onUrlChanged: signonRequest.currentUrl = url
2322
24 context: UbuntuWebContext {23 context: UbuntuWebContext {
25 dataPath: rootDir24 dataPath: signonRequest.rootDir
26 }25 }
27}26}
2827
=== modified file 'src/module/qmldir.in'
--- src/module/qmldir.in 2013-06-05 11:33:39 +0000
+++ src/module/qmldir.in 2014-08-11 13:15:20 +0000
@@ -1,7 +1,9 @@
1module $${API_URI}1module $${API_URI}
2KeyboardRectangle 1.0 KeyboardRectangle.qml
2OAuthMain 1.0 OAuthMain.qml3OAuthMain 1.0 OAuthMain.qml
3OAuth 1.0 OAuth.qml4OAuth 1.0 OAuth.qml
4Options 1.0 Options.qml5Options 1.0 Options.qml
5RemovalConfirmation 1.0 RemovalConfirmation.qml6RemovalConfirmation 1.0 RemovalConfirmation.qml
6ServiceItem 1.0 ServiceItem.qml7ServiceItem 1.0 ServiceItem.qml
7ServiceSwitches 1.0 ServiceSwitches.qml8ServiceSwitches 1.0 ServiceSwitches.qml
9WebView 1.0 WebView.qml
810
=== modified file 'src/notification.cpp'
--- src/notification.cpp 2014-06-05 13:28:30 +0000
+++ src/notification.cpp 2014-08-11 13:15:20 +0000
@@ -108,6 +108,14 @@
108 this, NULL);108 this, NULL);
109}109}
110110
111void Notification::setSnapDecision(bool snapDecision)
112{
113 Q_D(Notification);
114 notify_notification_set_hint(d->m_notification,
115 "x-canonical-snap-decisions",
116 g_variant_new_boolean(snapDecision));
117}
118
111void Notification::show()119void Notification::show()
112{120{
113 Q_D(Notification);121 Q_D(Notification);
114122
=== modified file 'src/notification.h'
--- src/notification.h 2014-06-05 13:28:30 +0000
+++ src/notification.h 2014-08-11 13:15:20 +0000
@@ -37,6 +37,7 @@
37 ~Notification();37 ~Notification();
3838
39 void addAction(const QString &action, const QString &label);39 void addAction(const QString &action, const QString &label);
40 void setSnapDecision(bool snapDecision);
4041
41public Q_SLOTS:42public Q_SLOTS:
42 void show();43 void show();
4344
=== modified file 'src/online-accounts-ui.pro'
--- src/online-accounts-ui.pro 2014-06-05 13:28:30 +0000
+++ src/online-accounts-ui.pro 2014-08-11 13:15:20 +0000
@@ -92,7 +92,8 @@
92 qml/NormalStartupPage.qml \92 qml/NormalStartupPage.qml \
93 qml/ProviderPluginList.qml \93 qml/ProviderPluginList.qml \
94 qml/ProviderRequest.qml \94 qml/ProviderRequest.qml \
95 qml/ProvidersList.qml95 qml/ProvidersList.qml \
96 qml/SignOnUiPage.qml
9697
97RESOURCES += \98RESOURCES += \
98 ui.qrc99 ui.qrc
99100
=== added file 'src/qml/SignOnUiPage.qml'
--- src/qml/SignOnUiPage.qml 1970-01-01 00:00:00 +0000
+++ src/qml/SignOnUiPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,40 @@
1import QtQuick 2.0
2import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem
4import Ubuntu.OnlineAccounts.Plugin 1.0
5
6MainView {
7 id: root
8
9 property var signonRequest: request
10
11 width: units.gu(60)
12 height: units.gu(90)
13
14 Page {
15 WebView {
16 id: loader
17 signonRequest: root.signonRequest
18
19 anchors {
20 fill: parent
21 bottomMargin: Math.max(osk.height, cancelButton.height)
22 }
23 }
24
25 ListItem.SingleControl {
26 id: cancelButton
27 anchors.bottom: parent.bottom
28 showDivider: false
29 control: Button {
30 text: i18n.dtr("ubuntu-system-settings-online-accounts", "Cancel")
31 width: parent.width - units.gu(4)
32 onClicked: signonRequest.cancel()
33 }
34 }
35
36 KeyboardRectangle {
37 id: osk
38 }
39 }
40}
041
=== modified file 'src/signonui-request.cpp'
--- src/signonui-request.cpp 2014-06-05 13:28:30 +0000
+++ src/signonui-request.cpp 2014-08-11 13:15:20 +0000
@@ -1,7 +1,7 @@
1/*1/*
2 * This file is part of online-accounts-ui2 * This file is part of online-accounts-ui
3 *3 *
4 * Copyright (C) 2011 Canonical Ltd.4 * Copyright (C) 2011-2014 Canonical Ltd.
5 *5 *
6 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>6 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7 *7 *
@@ -20,13 +20,16 @@
2020
21#include "signonui-request.h"21#include "signonui-request.h"
2222
23#include "account-manager.h"
24#include "application-manager.h"
23#include "browser-request.h"25#include "browser-request.h"
24#include "debug.h"26#include "debug.h"
25#include "globals.h"27#include "globals.h"
26#include "indicator-service.h"28#include "notification.h"
2729
28#include <Accounts/Account>30#include <Accounts/Account>
29#include <Accounts/Manager>31#include <Accounts/Application>
32#include <Accounts/Provider>
30#include <QDBusArgument>33#include <QDBusArgument>
31#include <SignOn/uisessiondata.h>34#include <SignOn/uisessiondata.h>
32#include <SignOn/uisessiondata_priv.h>35#include <SignOn/uisessiondata_priv.h>
@@ -45,16 +48,19 @@
45 ~RequestPrivate();48 ~RequestPrivate();
4649
47private:50private:
48 bool setWindow(QWindow *window);51 void setWindow(QWindow *window);
49 Accounts::Account *findAccount();52 Accounts::Account *findAccount();
50 bool dispatchToIndicator();53
54private Q_SLOTS:
55 void onActionInvoked(const QString &action);
56 void onNotificationClosed();
5157
52private:58private:
53 mutable Request *q_ptr;59 mutable Request *q_ptr;
54 QVariantMap m_clientData;60 QVariantMap m_clientData;
55 bool m_inProgress;
56 RequestHandler *m_handler;61 RequestHandler *m_handler;
57 Accounts::Manager *m_accountManager;62 OnlineAccountsUi::Notification *m_notification;
63 QWindow *m_window;
58};64};
5965
60} // namespace66} // namespace
@@ -62,9 +68,9 @@
62RequestPrivate::RequestPrivate(Request *request):68RequestPrivate::RequestPrivate(Request *request):
63 QObject(request),69 QObject(request),
64 q_ptr(request),70 q_ptr(request),
65 m_inProgress(false),
66 m_handler(0),71 m_handler(0),
67 m_accountManager(0)72 m_notification(0),
73 m_window(0)
68{74{
69 const QVariantMap &parameters = request->parameters();75 const QVariantMap &parameters = request->parameters();
70 if (parameters.contains(SSOUI_KEY_CLIENT_DATA)) {76 if (parameters.contains(SSOUI_KEY_CLIENT_DATA)) {
@@ -77,20 +83,51 @@
7783
78RequestPrivate::~RequestPrivate()84RequestPrivate::~RequestPrivate()
79{85{
86 delete m_notification;
87 m_notification = 0;
80}88}
8189
82bool RequestPrivate::setWindow(QWindow *window)90void RequestPrivate::setWindow(QWindow *window)
83{91{
84 Q_Q(Request);92 Q_Q(Request);
85 Q_UNUSED(window);
8693
87 /* If the window has no parent and the webcredentials indicator service is94 /* Don't show the window yet: the user must be presented with a
88 * up, dispatch the request to it. */95 * snap-decision, and we'll show the window only if he decides to
89 if (q->windowId() == 0 && dispatchToIndicator()) {96 * authenticate. */
90 return true;97 Accounts::Account *account = findAccount();
98 if (Q_UNLIKELY(!account)) {
99 QVariantMap result;
100 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
101 q->setResult(result);
102 return;
91 }103 }
92104
93 return false;105 OnlineAccountsUi::ApplicationManager *appManager =
106 OnlineAccountsUi::ApplicationManager::instance();
107 Accounts::Application application =
108 appManager->applicationFromProfile(q->clientApparmorProfile());
109
110 OnlineAccountsUi::AccountManager *accountManager =
111 OnlineAccountsUi::AccountManager::instance();
112 Accounts::Provider provider =
113 accountManager->provider(account->providerName());
114
115 QString summary =
116 QString("Please authorize %1 to access your %2 account %3").
117 arg(application.isValid() ? application.displayName() : "Ubuntu").
118 arg(provider.displayName()).
119 arg(account->displayName());
120 m_notification =
121 new OnlineAccountsUi::Notification("Authentication request", summary);
122 m_notification->addAction("cancel", "Cancel");
123 m_notification->addAction("continue", "Authorize...");
124 m_notification->setSnapDecision(true);
125 QObject::connect(m_notification, SIGNAL(actionInvoked(const QString &)),
126 this, SLOT(onActionInvoked(const QString &)));
127 QObject::connect(m_notification, SIGNAL(closed()),
128 this, SLOT(onNotificationClosed()));
129 m_notification->show();
130 m_window = window;
94}131}
95132
96Accounts::Account *RequestPrivate::findAccount()133Accounts::Account *RequestPrivate::findAccount()
@@ -104,11 +141,10 @@
104 /* Find the account using this identity.141 /* Find the account using this identity.
105 * FIXME: there might be more than one!142 * FIXME: there might be more than one!
106 */143 */
107 if (m_accountManager == 0) {144 OnlineAccountsUi::AccountManager *manager =
108 m_accountManager = new Accounts::Manager(this);145 OnlineAccountsUi::AccountManager::instance();
109 }146 Q_FOREACH(Accounts::AccountId accountId, manager->accountList()) {
110 Q_FOREACH(Accounts::AccountId accountId, m_accountManager->accountList()) {147 Accounts::Account *account = manager->account(accountId);
111 Accounts::Account *account = m_accountManager->account(accountId);
112 if (account == 0) continue;148 if (account == 0) continue;
113149
114 QVariant value(QVariant::UInt);150 QVariant value(QVariant::UInt);
@@ -122,34 +158,40 @@
122 return 0;158 return 0;
123}159}
124160
125bool RequestPrivate::dispatchToIndicator()161void RequestPrivate::onActionInvoked(const QString &action)
126{162{
127 Q_Q(Request);163 Q_Q(Request);
128164
129 Accounts::Account *account = findAccount();165 DEBUG() << action;
130 if (account == 0) {166
131 return false;167 QObject::disconnect(m_notification, 0, this, 0);
168 m_notification->deleteLater();
169 m_notification = 0;
170
171 if (action == QStringLiteral("continue")) {
172 q->setWindow(m_window);
173 } else {
174 q->cancel();
132 }175 }
133176}
134 QVariantMap notification;177
135 notification["DisplayName"] = account->displayName();178void RequestPrivate::onNotificationClosed()
136 notification["ClientData"] = m_clientData;179{
137 notification["Identity"] = q->identity();180 Q_Q(Request);
138 notification["Method"] = q->method();181
139 notification["Mechanism"] = q->mechanism();182 DEBUG();
140183
141 IndicatorService *indicator = IndicatorService::instance();184 /* setResult() should have been called by onActionInvoked(), but calling it
142 indicator->reportFailure(account->id(), notification);185 * twice won't harm because only the first invocation counts. */
143
144 /* the account has been reported as failing. We can now close this
145 * request, and tell the application that UI interaction is forbidden.
146 */
147 QVariantMap result;186 QVariantMap result;
148 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;187 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
149 q->setResult(result);188 q->setResult(result);
150 return true;189
190 m_notification->deleteLater();
191 m_notification = 0;
151}192}
152193
194#ifndef NO_REQUEST_FACTORY
153Request *Request::newRequest(const QDBusConnection &connection,195Request *Request::newRequest(const QDBusConnection &connection,
154 const QDBusMessage &message,196 const QDBusMessage &message,
155 const QVariantMap &parameters,197 const QVariantMap &parameters,
@@ -162,6 +204,7 @@
162 return 0; // TODO new DialogRequest(connection, message, parameters, parent);204 return 0; // TODO new DialogRequest(connection, message, parameters, parent);
163 }205 }
164}206}
207#endif
165208
166Request::Request(const QDBusConnection &connection,209Request::Request(const QDBusConnection &connection,
167 const QDBusMessage &message,210 const QDBusMessage &message,
@@ -189,8 +232,22 @@
189void Request::setWindow(QWindow *window)232void Request::setWindow(QWindow *window)
190{233{
191 Q_D(Request);234 Q_D(Request);
192 if (!d->setWindow(window))235
236 /* While a notification is shown, ignore any further calls to
237 * setWindow(). */
238 if (d->m_notification) return;
239
240 /* The first time that this method is called, we handle it by presenting a
241 * snap decision to the user.
242 * Then, if this is called again with the same QWindow, it means that the
243 * snap decision was accepted, and we show the window.
244 */
245 if (window == d->m_window) {
193 OnlineAccountsUi::Request::setWindow(window);246 OnlineAccountsUi::Request::setWindow(window);
247 d->m_window = 0;
248 } else {
249 d->setWindow(window);
250 }
194}251}
195252
196uint Request::identity() const253uint Request::identity() const
@@ -232,12 +289,10 @@
232289
233void Request::setCanceled()290void Request::setCanceled()
234{291{
235 if (isInProgress()) {292 QVariantMap result;
236 QVariantMap result;293 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_CANCELED;
237 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_CANCELED;
238294
239 setResult(result);295 setResult(result);
240 }
241}296}
242297
243#include "signonui-request.moc"298#include "signonui-request.moc"
244299
=== modified file 'src/ui.qrc'
--- src/ui.qrc 2014-03-19 12:14:14 +0000
+++ src/ui.qrc 2014-08-11 13:15:20 +0000
@@ -13,5 +13,6 @@
13 <file>qml/ProviderPluginList.qml</file>13 <file>qml/ProviderPluginList.qml</file>
14 <file>qml/ProviderRequest.qml</file>14 <file>qml/ProviderRequest.qml</file>
15 <file>qml/ProvidersList.qml</file>15 <file>qml/ProvidersList.qml</file>
16 <file>qml/SignOnUiPage.qml</file>
16</qresource>17</qresource>
17</RCC>18</RCC>
1819
=== added file 'system-settings-plugin/AccountEditPage.qml'
--- system-settings-plugin/AccountEditPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/AccountEditPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.OnlineAccounts 0.1
22
23// HACK
24import Ubuntu.OnlineAccounts.Plugin 1.0
25
26Page {
27 id: root
28
29 property variant accountHandle
30
31 signal finished
32
33 title: account.provider.displayName
34
35 Account {
36 id: account
37 objectHandle: accountHandle
38 }
39
40/* Loader {
41 id: loader
42 property var account: account
43
44 anchors.fill: parent
45 source: localQmlPluginPath + account.provider.id + "/Main.qml"
46
47 onStatusChanged: {
48 if (loader.status == Loader.Error) {
49 loader.source = systemQmlPluginPath + account.provider.id + "/Main.qml"
50 }
51 }
52
53
54 Connections {
55 target: loader.item
56 onFinished: {
57 console.log("====== PLUGIN FINISHED ======")
58 root.finished()
59 }
60 }
61 }
62*/
63 // HACK: this only suppots OAuth-based providers...
64 OAuthMain {}
65
66}
067
=== added file 'system-settings-plugin/AccountItem.qml'
--- system-settings-plugin/AccountItem.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/AccountItem.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22import Ubuntu.OnlineAccounts 0.1
23
24ListItem.Subtitled {
25 property variant accountHandle
26 property variant globalServiceHandle
27 property variant __editPage: null
28 property bool running: false
29
30 iconName: globalService.provider.iconName
31 progression: true
32 opacity: globalService.enabled ? 1 : 0.5
33
34 resources: [
35 AccountService {
36 id: globalService
37 objectHandle: globalServiceHandle
38 },
39 Component {
40 id: accountEditPage
41 AccountEditPage {}
42 }
43 ]
44
45 onClicked: {
46 __editPage = accountEditPage.createObject(null, {
47 "accountHandle": accountHandle })
48 __editPage.finished.connect(__onEditFinished)
49 pageStack.push(__editPage)
50 running = true;
51 }
52
53 function __onEditFinished() {
54 __editPage.destroy(1000)
55 __editPage = null
56 pageStack.pop()
57 running = false
58 }
59}
060
=== added file 'system-settings-plugin/AccountsPage.qml'
--- system-settings-plugin/AccountsPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/AccountsPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22
23Flickable {
24 id: root
25 property variant accountsModel
26 contentHeight: contentItem.childrenRect.height
27 boundsBehavior: Flickable.StopAtBounds
28
29 Column {
30 anchors.left: parent.left
31 anchors.right: parent.right
32
33 ListView {
34 anchors.left: parent.left
35 anchors.right: parent.right
36 interactive: false
37 height: contentHeight
38 model: accountsModel
39
40 delegate: AccountItem {
41 ListView.delayRemove: running
42 text: providerName
43 subText: displayName
44 accountHandle: model.accountHandle
45 globalServiceHandle: accountServiceHandle
46 }
47 }
48
49 ListItem.SingleControl {
50 control: Button {
51 text: i18n.tr("Add account…")
52 width: parent.width - units.gu(4)
53 onClicked: pageStack.push(newAccountPage)
54 }
55 showDivider: false
56 }
57
58 AddAccountLabel {}
59 }
60
61 Component {
62 id: newAccountPage
63 NewAccountPage {}
64 }
65}
066
=== added file 'system-settings-plugin/AddAccountLabel.qml'
--- system-settings-plugin/AddAccountLabel.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/AddAccountLabel.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22
23ListItem.Caption {
24 anchors.left: parent.left
25 anchors.right: parent.right
26 anchors.margins: units.gu(2)
27 text: i18n.tr("Storing account details here lets apps use the accounts without you having to sign in for each app.")
28}
029
=== added file 'system-settings-plugin/AuthorizationPage.qml'
--- system-settings-plugin/AuthorizationPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/AuthorizationPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22
23Flickable {
24 id: root
25
26 property variant model
27 property variant application
28 property variant provider
29
30 signal allowed(int accountId)
31 signal denied
32 signal createAccount
33
34 Column {
35 anchors.left: parent.left
36 anchors.right: parent.right
37
38 Label {
39 anchors.left: parent.left
40 anchors.right: parent.right
41 text: i18n.tr("%1 wants to access your %2 account").
42 arg(application.displayName).arg(provider.displayName);
43 wrapMode: Text.WordWrap
44 }
45
46 ListItem.ItemSelector {
47 id: accountSelector
48 anchors.left: parent.left
49 anchors.right: parent.right
50 text: "Account"
51 model: root.model
52 delegate: OptionSelectorDelegate {
53 property string modelData: model.displayName
54 }
55 onDelegateClicked: {
56 /* The last item in the model is the "Add another..." label */
57 if (index == model.count - 1) root.createAccount();
58 }
59 }
60
61 Button {
62 anchors.horizontalCenter: parent.horizontalCenter
63 width: parent.width - units.gu(4)
64 text: i18n.tr("Allow")
65 onClicked: root.allowed(root.model.get(accountSelector.selectedIndex, "accountId"))
66 }
67
68 Button {
69 anchors.horizontalCenter: parent.horizontalCenter
70 width: parent.width - units.gu(4)
71 text: i18n.tr("Don't allow")
72 onClicked: root.denied()
73 }
74 }
75}
076
=== added file 'system-settings-plugin/EntryComponent.qml'
--- system-settings-plugin/EntryComponent.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/EntryComponent.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,33 @@
1/*
2 * This file is part of system-settings
3 *
4 * Copyright (C) 2013 Canonical Ltd.
5 *
6 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21import QtQuick 2.0
22import Ubuntu.Components 0.1
23import Ubuntu.Components.ListItems 0.1 as ListItem
24
25ListItem.Standard {
26 id: root
27
28 objectName: "entryComponent-about"
29 iconSource: Qt.resolvedUrl(model.icon)
30 iconFrame: false
31 text: i18n.tr(model.displayName)
32 progression: true
33}
034
=== added file 'system-settings-plugin/MainPage.qml'
--- system-settings-plugin/MainPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/MainPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import SystemSettings 1.0
21import Ubuntu.Components 0.1
22import Ubuntu.Components.ListItems 0.1 as ListItem
23import Ubuntu.OnlineAccounts 0.1
24
25ItemPage {
26 id: root
27 objectName: "accountsPage"
28
29 title: i18n.tr("Accounts")
30
31 // OnlineAccountsPanel {
32 // id: onlineAccountsPanel
33 // }
34
35 property Item flickable: accountsPage.visible ? accountsPage : noAccountsPage
36
37 AccountServiceModel {
38 id: accountsModel
39 service: "global"
40 includeDisabled: true
41 }
42
43 AccountsPage {
44 id: accountsPage
45 anchors.fill: parent
46 accountsModel: accountsModel
47 visible: accountsModel.count > 0
48 }
49
50 NoAccountsPage {
51 id: noAccountsPage
52 anchors.fill: parent
53 accountsModel: accountsModel
54 visible:!accountsPage.visible
55 }
56
57
58 Component {
59 id: accountCreationPage
60 AccountCreationPage {
61 providerId: pluginOptions.provider
62 }
63 }
64
65}
66
067
=== added file 'system-settings-plugin/NewAccountPage.qml'
--- system-settings-plugin/NewAccountPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/NewAccountPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21
22Page {
23 title: i18n.tr("Add account")
24
25 Flickable {
26 anchors.fill: parent
27 contentHeight: contentItem.childrenRect.height
28 boundsBehavior: Flickable.StopAtBounds
29
30 ProviderPluginList {
31 onCreationFinished: {
32 // pop the creation page and this page (go back to parent page)
33 pageStack.pop()
34 pageStack.pop()
35 }
36 }
37 }
38}
039
=== added file 'system-settings-plugin/NoAccountsPage.qml'
--- system-settings-plugin/NoAccountsPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/NoAccountsPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22
23Flickable {
24 id: root
25
26 property variant accountsModel
27 contentHeight: contentItem.childrenRect.height
28 boundsBehavior: Flickable.StopAtBounds
29
30 Column {
31 anchors.left: parent.left
32 anchors.right: parent.right
33
34 ListItem.Base {
35 Label {
36 text: i18n.tr("No accounts")
37 anchors.centerIn: parent
38 }
39 }
40
41 AddAccountLabel {}
42
43 ListItem.Standard {
44 text: i18n.tr("Add account:")
45 }
46
47 ProviderPluginList {
48 onCreationFinished: {
49 // pop the creation page; remain in this page
50 pageStack.pop()
51 }
52 }
53 }
54}
055
=== added file 'system-settings-plugin/NormalStartupPage.qml'
--- system-settings-plugin/NormalStartupPage.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/NormalStartupPage.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.OnlineAccounts 0.1
21
22Item {
23 id: root
24
25 property Item flickable: accountsPage.visible ? accountsPage : noAccountsPage
26
27 AccountServiceModel {
28 id: accountsModel
29 service: "global"
30 includeDisabled: true
31 }
32
33 AccountsPage {
34 id: accountsPage
35 anchors.fill: parent
36 accountsModel: accountsModel
37 visible: accountsModel.count > 0
38 }
39
40 NoAccountsPage {
41 id: noAccountsPage
42 anchors.fill: parent
43 accountsModel: accountsModel
44 visible: !accountsPage.visible
45 }
46}
047
=== added file 'system-settings-plugin/ProviderPluginList.qml'
--- system-settings-plugin/ProviderPluginList.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/ProviderPluginList.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,42 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21
22ProvidersList {
23 id: root
24
25 property variant __creationPage: null
26
27 signal creationFinished
28
29 onProviderClicked: {
30 __creationPage = accountCreationPage.createObject(null, {
31 "providerId": providerId })
32 __creationPage.finished.connect(__onCreationFinished)
33 pageStack.push(__creationPage)
34 }
35
36 function __onCreationFinished() {
37 __creationPage.destroy(1000)
38 __creationPage.finished.disconnect(__onCreationFinished)
39 __creationPage = null
40 creationFinished()
41 }
42}
043
=== added file 'system-settings-plugin/ProvidersList.qml'
--- system-settings-plugin/ProvidersList.qml 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/ProvidersList.qml 2014-08-11 13:15:20 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1 as ListItem
22import Ubuntu.OnlineAccounts 0.1
23
24Column {
25 id: root
26
27 signal providerClicked(string providerId)
28
29 anchors.left: parent.left
30 anchors.right: parent.right
31
32 ProviderModel {
33 id: providerModel
34 }
35
36 Repeater {
37 model: providerModel
38
39 delegate: ListItem.Standard {
40 text: displayName
41 enabled: !isSingleAccount || hasNoAccounts(providerId)
42 iconName: model.iconName
43 progression: true
44 onClicked: root.providerClicked(providerId)
45 }
46 }
47
48 Component {
49 id: accountModel
50 AccountServiceModel {
51 includeDisabled: true
52 }
53 }
54
55 function hasNoAccounts(providerId) {
56 var model = accountModel.createObject(null, {
57 "provider": providerId })
58 var hasAccounts = (model.count > 0)
59 model.destroy()
60 return !hasAccounts
61 }
62}
063
=== modified file 'system-settings-plugin/online-accounts.settings'
--- system-settings-plugin/online-accounts.settings 2013-09-09 10:56:53 +0000
+++ system-settings-plugin/online-accounts.settings 2014-08-11 13:15:20 +0000
@@ -11,5 +11,6 @@
11 ],11 ],
12 "has-dynamic-keywords": true,12 "has-dynamic-keywords": true,
13 "has-dynamic-visibility": false,13 "has-dynamic-visibility": false,
14 "plugin": "online-accounts"14 "entry-component": "EntryComponent.qml",
15 "page-component": "MainPage.qml"
15}16}
1617
=== modified file 'system-settings-plugin/plugin.cpp'
--- system-settings-plugin/plugin.cpp 2014-05-30 08:55:40 +0000
+++ system-settings-plugin/plugin.cpp 2014-08-11 13:15:20 +0000
@@ -16,74 +16,21 @@
16 * with this program. If not, see <http://www.gnu.org/licenses/>.16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */17 */
1818
19#include <QtQml>
20#include <QtQml/QQmlContext>
19#include "plugin.h"21#include "plugin.h"
2022// #include "accounts.h"
21#include <OnlineAccountsClient/Setup>23
22#include <QDebug>24
23#include <QStringList>25void BackendPlugin::registerTypes(const char *uri)
24#include <SystemSettings/ItemBase>26{
2527 Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.OnlineAccounts"));
26using namespace SystemSettings;28
2729 qDebug() << uri;
28class Item: public ItemBase30 // qmlRegisterType<OnlineAccounts>(uri, 1, 0, "OnlineAccountsPanel");
29{31}
30 Q_OBJECT32
3133void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
32public:34{
33 Item(const QVariantMap &staticData, QObject *parent = 0);35 QQmlExtensionPlugin::initializeEngine(engine, uri);
34 ~Item();36}
35
36 QQmlComponent *pageComponent(QQmlEngine *engine,
37 QObject *parent = 0) Q_DECL_OVERRIDE;
38
39private Q_SLOTS:
40 void onFinished();
41
42private:
43 OnlineAccountsClient::Setup m_setup;
44 bool m_isOpen;
45};
46
47Item::Item(const QVariantMap &staticData, QObject *parent):
48 ItemBase(staticData, parent),
49 m_isOpen(false)
50{
51 QObject::connect(&m_setup, SIGNAL(finished()),
52 this, SLOT(onFinished()));
53}
54
55Item::~Item()
56{
57}
58
59QQmlComponent *Item::pageComponent(QQmlEngine *engine,
60 QObject *parent)
61{
62 Q_UNUSED(engine);
63 Q_UNUSED(parent);
64
65 if (!m_isOpen) {
66 qDebug() << "Opening Online Accounts";
67 m_isOpen = true;
68 m_setup.exec();
69 }
70 return 0;
71}
72
73void Item::onFinished()
74{
75 m_isOpen = false;
76}
77
78Plugin::Plugin():
79 QObject()
80{
81}
82
83ItemBase *Plugin::createItem(const QVariantMap &staticData,
84 QObject *parent)
85{
86 return new Item(staticData, parent);
87}
88
89#include "plugin.moc"
9037
=== modified file 'system-settings-plugin/plugin.h'
--- system-settings-plugin/plugin.h 2013-09-09 10:56:53 +0000
+++ system-settings-plugin/plugin.h 2014-08-11 13:15:20 +0000
@@ -19,20 +19,17 @@
19#ifndef ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H19#ifndef ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
20#define ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H20#define ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
2121
22#include <QObject>22#include <QtQml/QQmlEngine>
23#include <SystemSettings/PluginInterface>23#include <QtQml/QQmlExtensionPlugin>
2424
25class Plugin: public QObject, public SystemSettings::PluginInterface25class BackendPlugin : public QQmlExtensionPlugin
26{26{
27 Q_OBJECT27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "com.ubuntu.SystemSettings.PluginInterface")28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29 Q_INTERFACES(SystemSettings::PluginInterface)
3029
31public:30public:
32 Plugin();31 void registerTypes(const char *uri);
3332 void initializeEngine(QQmlEngine *engine, const char *uri);
34 SystemSettings::ItemBase *createItem(const QVariantMap &staticData,
35 QObject *parent = 0);
36};33};
3734
38#endif // ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H35#endif // ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
3936
=== modified file 'system-settings-plugin/system-settings-plugin.pro'
--- system-settings-plugin/system-settings-plugin.pro 2013-09-09 10:56:53 +0000
+++ system-settings-plugin/system-settings-plugin.pro 2014-08-11 13:15:20 +0000
@@ -4,6 +4,21 @@
4TEMPLATE = lib4TEMPLATE = lib
5TARGET = online-accounts5TARGET = online-accounts
66
7QML_SOURCES = \
8 AccountEditPage.qml \
9 AccountCreationPage.qml \
10 AuthorizationPage.qml \
11 NoAccountsPage.qml \
12 AccountItem.qml \
13 EntryComponent.qml \
14 NormalStartupPage.qml \
15 AccountsPage.qml \
16 MainPage.qml \
17 ProviderPluginList.qml \
18 AddAccountLabel.qml \
19 NewAccountPage.qml \
20 ProvidersList.qml
21
7CONFIG += \22CONFIG += \
8 link_pkgconfig \23 link_pkgconfig \
9 plugin \24 plugin \
@@ -39,3 +54,6 @@
39image.path = $${PLUGIN_MANIFEST_DIR}/icons54image.path = $${PLUGIN_MANIFEST_DIR}/icons
40INSTALLS += image55INSTALLS += image
4156
57qml.files = $${QML_SOURCES}
58qml.path = $${PLUGIN_QML_DIR}/online-accounts
59INSTALLS += qml
4260
=== added file 'tests/online-accounts-ui/data/com.ubuntu.tests_application.application'
--- tests/online-accounts-ui/data/com.ubuntu.tests_application.application 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/data/com.ubuntu.tests_application.application 2014-08-11 13:15:20 +0000
@@ -0,0 +1,19 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2<application id="com.ubuntu.tests_application">
3 <description>Mailer</description>
4 <translations>mailer-catalog</translations>
5 <desktop-entry>mailer.desktop</desktop-entry>
6
7 <service-types>
8 <service-type id="e-mail">
9 <description>Mailer can retrieve your e-mails</description>
10 </service-type>
11 </service-types>
12
13 <services>
14 <service id="coolshare">
15 <description>Mailer can even share stuff on CoolShare</description>
16 </service>
17 </services>
18 <profile>com.ubuntu.tests_application_0.3</profile>
19</application>
020
=== added file 'tests/online-accounts-ui/mock/notification-mock.cpp'
--- tests/online-accounts-ui/mock/notification-mock.cpp 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/mock/notification-mock.cpp 2014-08-11 13:15:20 +0000
@@ -0,0 +1,81 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "notification-mock.h"
22
23#include <QByteArray>
24#include <QDebug>
25#include <QString>
26
27using namespace OnlineAccountsUi;
28
29QList<Notification*> NotificationPrivate::allNotifications;
30
31NotificationPrivate::NotificationPrivate(const QString &summary,
32 const QString &body,
33 Notification *notification):
34 QObject(notification),
35 m_summary(summary),
36 m_body(body),
37 q_ptr(notification)
38{
39 allNotifications.append(notification);
40}
41
42NotificationPrivate::~NotificationPrivate()
43{
44 allNotifications.removeAll(q_ptr);
45}
46
47void NotificationPrivate::invokeAction(const QString &action)
48{
49 Q_Q(Notification);
50 Q_EMIT q->actionInvoked(action);
51}
52
53Notification::Notification(const QString &summary,
54 const QString &body,
55 QObject *parent):
56 QObject(parent),
57 d_ptr(new NotificationPrivate(summary, body, this))
58{
59}
60
61Notification::~Notification()
62{
63}
64
65void Notification::addAction(const QString &action, const QString &label)
66{
67 Q_D(Notification);
68 d->m_actions.append(ActionPair(action, label));
69}
70
71void Notification::setSnapDecision(bool snapDecision)
72{
73 Q_D(Notification);
74 d->m_isSnapDecision = snapDecision;
75}
76
77void Notification::show()
78{
79 Q_D(Notification);
80 Q_EMIT d->showCalled();
81}
082
=== added file 'tests/online-accounts-ui/mock/notification-mock.h'
--- tests/online-accounts-ui/mock/notification-mock.h 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/mock/notification-mock.h 2014-08-11 13:15:20 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef MOCK_NOTIFICATiON_H
22#define MOCK_NOTIFICATiON_H
23
24#include "notification.h"
25
26#include <QByteArray>
27#include <QList>
28#include <QPair>
29#include <QString>
30
31using namespace OnlineAccountsUi;
32
33namespace OnlineAccountsUi {
34
35typedef QPair<QString,QString> ActionPair;
36
37class NotificationPrivate: public QObject
38{
39 Q_OBJECT
40 Q_DECLARE_PUBLIC(Notification)
41
42public:
43 NotificationPrivate(const QString &summary,
44 const QString &body,
45 Notification *notification);
46 ~NotificationPrivate();
47 static NotificationPrivate *mocked(Notification *n) { return n->d_ptr; }
48
49 static QList<Notification *> allNotifications;
50
51 void invokeAction(const QString &action);
52
53Q_SIGNALS:
54 void showCalled();
55
56public:
57 QString m_summary;
58 QString m_body;
59 QList<ActionPair> m_actions;
60 bool m_isSnapDecision;
61 mutable Notification *q_ptr;
62};
63
64} // namespace
65
66#endif // MOCK_NOTIFICATiON_H
067
=== added file 'tests/online-accounts-ui/mock/request-mock.cpp'
--- tests/online-accounts-ui/mock/request-mock.cpp 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/mock/request-mock.cpp 2014-08-11 13:15:20 +0000
@@ -0,0 +1,136 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "globals.h"
22#include "request-mock.h"
23
24#include <QDebug>
25
26using namespace OnlineAccountsUi;
27
28RequestPrivate::RequestPrivate(const QDBusConnection &connection,
29 const QDBusMessage &message,
30 const QVariantMap &parameters,
31 Request *request):
32 QObject(request),
33 q_ptr(request),
34 m_parameters(parameters),
35 m_window(0),
36 m_inProgress(false)
37{
38 Q_UNUSED(connection);
39 Q_UNUSED(message);
40}
41
42RequestPrivate::~RequestPrivate()
43{
44}
45
46Request::Request(const QDBusConnection &connection,
47 const QDBusMessage &message,
48 const QVariantMap &parameters,
49 QObject *parent):
50 QObject(parent),
51 d_ptr(new RequestPrivate(connection, message, parameters, this))
52{
53}
54
55Request::~Request()
56{
57}
58
59void Request::setWindow(QWindow *window)
60{
61 Q_D(Request);
62 Q_EMIT d->setWindowCalled(window);
63}
64
65WId Request::windowId() const
66{
67 Q_D(const Request);
68 return d->m_parameters[OAU_KEY_WINDOW_ID].toUInt();
69}
70
71bool Request::isInProgress() const
72{
73 Q_D(const Request);
74 return d->m_inProgress;
75}
76
77const QVariantMap &Request::parameters() const
78{
79 Q_D(const Request);
80 return d->m_parameters;
81}
82
83QString Request::clientApparmorProfile() const
84{
85 Q_D(const Request);
86 return d->m_clientApparmorProfile;
87}
88
89QWindow *Request::window() const
90{
91 Q_D(const Request);
92 return d->m_window;
93}
94
95void Request::start()
96{
97 Q_D(Request);
98 if (d->m_inProgress) {
99 qWarning() << "Request already started!";
100 return;
101 }
102 d->m_inProgress = true;
103}
104
105void Request::cancel()
106{
107 setCanceled();
108}
109
110void Request::fail(const QString &name, const QString &message)
111{
112 Q_D(Request);
113 Q_EMIT d->failCalled(name, message);
114
115 Q_EMIT completed();
116}
117
118void Request::setCanceled()
119{
120 Q_D(Request);
121 if (d->m_inProgress) {
122 fail(OAU_ERROR_USER_CANCELED, QStringLiteral("Canceled"));
123 d->m_inProgress = false;
124 }
125}
126
127void Request::setResult(const QVariantMap &result)
128{
129 Q_D(Request);
130 if (d->m_inProgress) {
131 Q_EMIT d->setResultCalled(result);
132
133 Q_EMIT completed();
134 d->m_inProgress = false;
135 }
136}
0137
=== added file 'tests/online-accounts-ui/mock/request-mock.h'
--- tests/online-accounts-ui/mock/request-mock.h 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/mock/request-mock.h 2014-08-11 13:15:20 +0000
@@ -0,0 +1,64 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef MOCK_REQUEST_H
22#define MOCK_REQUEST_H
23
24#include "request.h"
25
26#include <QObject>
27#include <QString>
28#include <QVariantMap>
29
30namespace OnlineAccountsUi {
31
32class RequestPrivate: public QObject
33{
34 Q_OBJECT
35 Q_DECLARE_PUBLIC(Request)
36
37public:
38 RequestPrivate(const QDBusConnection &connection,
39 const QDBusMessage &message,
40 const QVariantMap &parameters,
41 Request *request);
42 ~RequestPrivate();
43 static RequestPrivate *mocked(Request *r) { return r->d_ptr; }
44
45 void setClientApparmorProfile(const QString &profile) {
46 m_clientApparmorProfile = profile;
47 }
48
49Q_SIGNALS:
50 void setWindowCalled(QWindow *);
51 void failCalled(const QString &name, const QString &message);
52 void setResultCalled(const QVariantMap &result);
53
54private:
55 mutable Request *q_ptr;
56 QVariantMap m_parameters;
57 QString m_clientApparmorProfile;
58 QWindow *m_window;
59 bool m_inProgress;
60};
61
62} // namespace
63
64#endif // MOCK_REQUEST_H
065
=== modified file 'tests/online-accounts-ui/online-accounts-ui.pro'
--- tests/online-accounts-ui/online-accounts-ui.pro 2014-06-05 13:28:30 +0000
+++ tests/online-accounts-ui/online-accounts-ui.pro 2014-08-11 13:15:20 +0000
@@ -5,4 +5,5 @@
5 tst_application_manager.pro \5 tst_application_manager.pro \
6 tst_inactivity_timer.pro \6 tst_inactivity_timer.pro \
7 tst_notification.pro \7 tst_notification.pro \
8 tst_service.pro8 tst_service.pro \
9 tst_signonui_request.pro
910
=== modified file 'tests/online-accounts-ui/tst_notification.cpp'
--- tests/online-accounts-ui/tst_notification.cpp 2014-06-05 13:28:30 +0000
+++ tests/online-accounts-ui/tst_notification.cpp 2014-08-11 13:15:20 +0000
@@ -26,6 +26,7 @@
26#include <QPair>26#include <QPair>
27#include <QSignalSpy>27#include <QSignalSpy>
28#include <QTest>28#include <QTest>
29#include <QVariantMap>
29#include <libnotify/notification.h>30#include <libnotify/notification.h>
30#include <libnotify/notify.h>31#include <libnotify/notify.h>
3132
@@ -52,6 +53,7 @@
52 QString summary;53 QString summary;
53 QString body;54 QString body;
54 QList<ActionPair> actions;55 QList<ActionPair> actions;
56 QVariantMap hints;
55 bool visible;57 bool visible;
5658
57 MockNotification();59 MockNotification();
@@ -167,6 +169,22 @@
167 callbackData.userData = user_data;169 callbackData.userData = user_data;
168}170}
169171
172void notify_notification_set_hint(NotifyNotification *notification,
173 const char *key,
174 GVariant *value)
175{
176 MockNotification *mock =
177 reinterpret_cast<MockNotification*>(notification);
178 QVariant variant;
179 if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
180 variant = bool(g_variant_get_boolean(value));
181 } else {
182 /* Add support for any needed types */
183 qWarning() << "Unsupported variant type";
184 }
185 mock->hints.insert(QString::fromUtf8(key), variant);
186}
187
170/* End of mock code */188/* End of mock code */
171189
172class NotificationTest: public QObject190class NotificationTest: public QObject
@@ -180,6 +198,7 @@
180 void testInitialization();198 void testInitialization();
181 void testDestruction();199 void testDestruction();
182 void testContents();200 void testContents();
201 void testSnapDecision();
183 void testVisibility();202 void testVisibility();
184 void testClosing();203 void testClosing();
185 void testActions();204 void testActions();
@@ -220,6 +239,20 @@
220 MockNotification *mock = *(notifications.begin());239 MockNotification *mock = *(notifications.begin());
221 QCOMPARE(mock->summary, QString("Summary"));240 QCOMPARE(mock->summary, QString("Summary"));
222 QCOMPARE(mock->body, QString("Body"));241 QCOMPARE(mock->body, QString("Body"));
242 QVERIFY(mock->hints.isEmpty());
243}
244
245void NotificationTest::testSnapDecision()
246{
247 Notification first("Summary", "Body");
248 MockNotification *mock = *(notifications.begin());
249 QVERIFY(mock->hints.isEmpty());
250
251 first.setSnapDecision(true);
252 QCOMPARE(mock->hints["x-canonical-snap-decisions"].toBool(), true);
253
254 first.setSnapDecision(false);
255 QCOMPARE(mock->hints["x-canonical-snap-decisions"].toBool(), false);
223}256}
224257
225void NotificationTest::testVisibility()258void NotificationTest::testVisibility()
226259
=== added file 'tests/online-accounts-ui/tst_signonui_request.cpp'
--- tests/online-accounts-ui/tst_signonui_request.cpp 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/tst_signonui_request.cpp 2014-08-11 13:15:20 +0000
@@ -0,0 +1,338 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "globals.h"
22#include "request-handler.h"
23#include "signonui-request.h"
24#include "mock/notification-mock.h"
25#include "mock/request-mock.h"
26
27#include <Accounts/Account>
28#include <Accounts/Manager>
29
30#include <QDebug>
31#include <QSignalSpy>
32#include <QTemporaryDir>
33#include <QTest>
34
35#include <SignOn/uisessiondata.h>
36#include <SignOn/uisessiondata_priv.h>
37
38using namespace OnlineAccountsUi;
39
40class TestRequest: public SignOnUi::Request
41{
42 Q_OBJECT
43
44public:
45 TestRequest(const QDBusConnection &connection,
46 const QDBusMessage &message,
47 const QVariantMap &parameters,
48 QObject *parent = 0):
49 Request(connection, message, parameters, parent)
50 {
51 }
52
53 void setWindow(QWindow *window) { Request::setWindow(window); }
54
55 void sendResult(const QVariantMap &result) { setResult(result); }
56};
57
58class SignonuiRequestTest: public QObject
59{
60 Q_OBJECT
61
62public:
63 SignonuiRequestTest();
64
65private Q_SLOTS:
66 void initTestCase();
67 void testParameters_data();
68 void testParameters();
69 void testHandler();
70 void testSnapDecision_data();
71 void testSnapDecision();
72
73private:
74 bool mustCreateAccount(uint credentialsId) { return credentialsId > 10; }
75
76private:
77 QDBusConnection m_connection;
78 QDBusMessage m_message;
79 QTemporaryDir m_accountsDir;
80};
81
82SignonuiRequestTest::SignonuiRequestTest():
83 QObject(),
84 m_connection(QStringLiteral("uninitialized"))
85{
86}
87
88void SignonuiRequestTest::initTestCase()
89{
90 QVERIFY(m_accountsDir.isValid());
91
92 qputenv("ACCOUNTS", m_accountsDir.path().toUtf8());
93 qputenv("AG_APPLICATIONS", TEST_DATA_DIR);
94 qputenv("AG_PROVIDERS", TEST_DATA_DIR);
95 qputenv("AG_SERVICES", TEST_DATA_DIR);
96 qputenv("XDG_DATA_HOME", TEST_DATA_DIR);
97}
98
99void SignonuiRequestTest::testParameters_data()
100{
101 QTest::addColumn<QVariantMap>("parameters");
102 QTest::addColumn<uint>("identity");
103 QTest::addColumn<QString>("method");
104 QTest::addColumn<QString>("mechanism");
105 QTest::addColumn<QString>("id");
106 QTest::addColumn<QVariantMap>("clientData");
107
108 QTest::newRow("empty") <<
109 QVariantMap() <<
110 uint(0) <<
111 QString() <<
112 QString() <<
113 QString() <<
114 QVariantMap();
115
116 QVariantMap clientData;
117 clientData.insert("some number", 4);
118
119 QVariantMap parameters;
120 parameters.insert(SSOUI_KEY_CLIENT_DATA, clientData);
121 parameters.insert(SSOUI_KEY_IDENTITY, uint(45));
122 parameters.insert(SSOUI_KEY_METHOD, QString("a method"));
123 parameters.insert(SSOUI_KEY_MECHANISM, QString("a mechanism"));
124 parameters.insert(SSOUI_KEY_REQUESTID, QString("/id-4"));
125
126
127 QTest::newRow("basic") <<
128 parameters <<
129 uint(45) <<
130 "a method" <<
131 "a mechanism" <<
132 "/id-4" <<
133 clientData;
134}
135
136void SignonuiRequestTest::testParameters()
137{
138 QFETCH(QVariantMap, parameters);
139 QFETCH(QString, method);
140 QFETCH(QString, mechanism);
141 QFETCH(QString, id);
142 QFETCH(QVariantMap, clientData);
143
144 TestRequest request(m_connection, m_message, parameters);
145 QCOMPARE(request.method(), method);
146 QCOMPARE(request.mechanism(), mechanism);
147 QCOMPARE(request.id(), id);
148 QCOMPARE(request.clientData(), clientData);
149}
150
151void SignonuiRequestTest::testHandler()
152{
153 QVariantMap parameters;
154 TestRequest request(m_connection, m_message, parameters);
155 QVERIFY(request.handler() == 0);
156
157 SignOnUi::RequestHandler *handler = new SignOnUi::RequestHandler;
158 request.setHandler(handler);
159 QCOMPARE(request.handler(), handler);
160
161 /* Try to set another handler; this won't be allowed */
162 SignOnUi::RequestHandler *handler2 = new SignOnUi::RequestHandler;
163 request.setHandler(handler2);
164 QCOMPARE(request.handler(), handler);
165
166 delete handler2;
167 delete handler;
168}
169
170void SignonuiRequestTest::testSnapDecision_data()
171{
172 QTest::addColumn<uint>("credentialsId");
173 QTest::addColumn<QString>("accountName");
174 QTest::addColumn<QString>("clientProfile");
175 QTest::addColumn<QString>("applicationName");
176 QTest::addColumn<bool>("mustAccept");
177 QTest::addColumn<QVariantMap>("result");
178
179 QVariantMap acceptedResult;
180 acceptedResult.insert("some key", QString("some value"));
181
182 QVariantMap declinedResult;
183 declinedResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_CANCELED);
184
185 QVariantMap errorResult;
186 errorResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_FORBIDDEN);
187
188 QTest::newRow("no account") <<
189 uint(0) <<
190 "tom@example.com" <<
191 "com.ubuntu.tests_application_0.3" <<
192 QString() <<
193 false <<
194 errorResult;
195
196 QTest::newRow("invalid account") <<
197 uint(1) <<
198 "tom@example.com" <<
199 "com.ubuntu.tests_application_0.3" <<
200 QString() <<
201 false <<
202 errorResult;
203
204 QTest::newRow("valid application, accepted") <<
205 uint(14231) <<
206 "tom@example.com" <<
207 "com.ubuntu.tests_application_0.3" <<
208 "Easy Mailer" <<
209 true <<
210 acceptedResult;
211
212 QTest::newRow("valid application, declined") <<
213 uint(14231) <<
214 "tom@example.com" <<
215 "com.ubuntu.tests_application_0.3" <<
216 "Easy Mailer" <<
217 false <<
218 declinedResult;
219
220 QTest::newRow("unconfined application, accepted") <<
221 uint(14235) <<
222 "tom@example.com" <<
223 "unconfined" <<
224 "Ubuntu" <<
225 true <<
226 acceptedResult;
227
228 QTest::newRow("unconfined application, declined") <<
229 uint(14235) <<
230 "tom@example.com" <<
231 "unconfined" <<
232 "Ubuntu" <<
233 false <<
234 declinedResult;
235}
236
237void SignonuiRequestTest::testSnapDecision()
238{
239 QString providerId("cool");
240 QFETCH(uint, credentialsId);
241 QFETCH(QString, accountName);
242 QFETCH(QString, clientProfile);
243 QFETCH(QString, applicationName);
244 QFETCH(bool, mustAccept);
245 QFETCH(QVariantMap, result);
246
247 // First, create an account
248 Accounts::Manager *manager = new Accounts::Manager(this);
249 Accounts::Provider provider = manager->provider(providerId);
250 QVERIFY(provider.isValid());
251 if (mustCreateAccount(credentialsId)) {
252 Accounts::Account *account = manager->createAccount(providerId);
253 QVERIFY(account != 0);
254 account->setEnabled(true);
255 account->setDisplayName(accountName);
256 account->setCredentialsId(credentialsId);
257 account->syncAndBlock();
258 }
259
260 /* Then, create a request referring to the same credentials ID of the
261 * created account. */
262 QVariantMap parameters;
263 parameters.insert(SSOUI_KEY_IDENTITY, credentialsId);
264 parameters.insert(SSOUI_KEY_METHOD, "funnyMethod");
265 parameters.insert(SSOUI_KEY_MECHANISM, "funnyMechanism");
266 TestRequest request(m_connection, m_message, parameters);
267 OnlineAccountsUi::RequestPrivate *mockRequest =
268 OnlineAccountsUi::RequestPrivate::mocked(&request);
269 QSignalSpy failCalled(mockRequest,
270 SIGNAL(failCalled(const QString&, const QString&)));
271 QSignalSpy setResultCalled(mockRequest,
272 SIGNAL(setResultCalled(const QVariantMap &)));
273 mockRequest->setClientApparmorProfile(clientProfile);
274 request.start();
275
276 /* Request to show a window; a snap decision should appear instead */
277 QWindow *window = new QWindow;
278 QSignalSpy setWindowCalled(mockRequest,
279 SIGNAL(setWindowCalled(QWindow*)));
280 request.setWindow(window);
281 QCOMPARE(setWindowCalled.count(), 0);
282 if (mustCreateAccount(credentialsId)) {
283 QCOMPARE(NotificationPrivate::allNotifications.count(), 1);
284 } else {
285 /* If the account is not found, no notification should appear, and an
286 * error returned to the app */
287 QCOMPARE(NotificationPrivate::allNotifications.count(), 0);
288 QCOMPARE(setResultCalled.count(), 1);
289 QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
290 return;
291 }
292
293 /* Inspect the snap decision contents */
294 Notification *notification =
295 NotificationPrivate::allNotifications.first();
296 NotificationPrivate *mockNotification =
297 NotificationPrivate::mocked(notification);
298 QCOMPARE(mockNotification->m_summary, QString("Authentication request"));
299 QCOMPARE(mockNotification->m_body,
300 QString("Please authorize %1 to access your %2 account %3").
301 arg(applicationName).arg(provider.displayName()).arg(accountName));
302 QVERIFY(mockNotification->m_isSnapDecision);
303
304 /* Invoke the action on the snap decision */
305 QString action = mustAccept ? "continue" : "cancel";
306 QSignalSpy actionInvoked(notification,
307 SIGNAL(actionInvoked(const QString &)));
308 mockNotification->invokeAction(action);
309 QCOMPARE(actionInvoked.count(), 1);
310 QCOMPARE(actionInvoked.at(0).at(0).toString(), action);
311
312 /* Here we iterate the main loop because the notification object is
313 * destroyed with deleteLater() */
314 QTest::qWait(5);
315
316 if (mustAccept) {
317 QCOMPARE(setWindowCalled.count(), 1);
318 QCOMPARE(setWindowCalled.at(0).at(0), QVariant::fromValue(window));
319 QCOMPARE(failCalled.count(), 0);
320 QCOMPARE(setResultCalled.count(), 0);
321
322 /* deliver the result */
323 request.sendResult(result);
324 QCOMPARE(setResultCalled.count(), 1);
325 QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
326 } else {
327 QCOMPARE(setWindowCalled.count(), 0);
328 QCOMPARE(failCalled.count(), 0);
329 QCOMPARE(setResultCalled.count(), 1);
330 QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
331 }
332 delete window;
333 delete manager;
334}
335
336QTEST_MAIN(SignonuiRequestTest);
337
338#include "tst_signonui_request.moc"
0339
=== added file 'tests/online-accounts-ui/tst_signonui_request.pro'
--- tests/online-accounts-ui/tst_signonui_request.pro 1970-01-01 00:00:00 +0000
+++ tests/online-accounts-ui/tst_signonui_request.pro 2014-08-11 13:15:20 +0000
@@ -0,0 +1,53 @@
1include(../../common-project-config.pri)
2
3TARGET = tst_signonui_request
4
5CONFIG += \
6 debug \
7 link_pkgconfig
8
9QT += \
10 core \
11 dbus \
12 testlib
13
14PKGCONFIG += \
15 accounts-qt5 \
16 libsignon-qt5 \
17 signon-plugins-common
18
19DEFINES += \
20 DEBUG_ENABLED \
21 NO_REQUEST_FACTORY \
22 TEST_DATA_DIR=\\\"$${PWD}/data\\\"
23
24SRCDIR = $${TOP_SRC_DIR}/src
25
26SOURCES += \
27 $${SRCDIR}/account-manager.cpp \
28 $${SRCDIR}/application-manager.cpp \
29 $${SRCDIR}/debug.cpp \
30 $${SRCDIR}/request-handler.cpp \
31 $${SRCDIR}/signonui-request.cpp \
32 mock/notification-mock.cpp \
33 mock/request-mock.cpp \
34 mock/qwindow.cpp \
35 tst_signonui_request.cpp
36
37HEADERS += \
38 $${SRCDIR}/account-manager.h \
39 $${SRCDIR}/application-manager.h \
40 $${SRCDIR}/notification.h \
41 $${SRCDIR}/request.h \
42 $${SRCDIR}/request-handler.h \
43 $${SRCDIR}/signonui-request.h \
44 mock/notification-mock.h \
45 mock/request-mock.h \
46 window-watcher.h
47
48INCLUDEPATH += \
49 $${SRCDIR}
50
51check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
52check.depends = $${TARGET}
53QMAKE_EXTRA_TARGETS += check

Subscribers

People subscribed via source and target branches