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
1=== modified file '.bzrignore'
2--- .bzrignore 2014-06-05 13:28:30 +0000
3+++ .bzrignore 2014-08-11 13:15:20 +0000
4@@ -46,3 +46,4 @@
5 /tests/online-accounts-ui/tst_inactivity_timer
6 /tests/online-accounts-ui/tst_notification
7 /tests/online-accounts-ui/tst_service
8+/tests/online-accounts-ui/tst_signonui_request
9
10=== modified file 'debian/control'
11--- debian/control 2014-06-04 12:00:43 +0000
12+++ debian/control 2014-08-11 13:15:20 +0000
13@@ -36,7 +36,6 @@
14 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,
15 signon-ui-service,
16 ubuntu-system-settings
17-Provides: signon-ui
18 Description: Online Accounts setup for Ubuntu Touch
19 Online Accounts setup utility for the Ubuntu Touch System Settings.
20
21
22=== modified file 'src/browser-request.cpp'
23--- src/browser-request.cpp 2014-04-29 14:34:44 +0000
24+++ src/browser-request.cpp 2014-08-11 13:15:20 +0000
25@@ -28,6 +28,7 @@
26
27 #include <QDir>
28 #include <QQmlContext>
29+#include <QQmlEngine>
30 #include <QStandardPaths>
31 #include <QTimer>
32 #include <SignOn/uisessiondata_priv.h>
33@@ -133,18 +134,9 @@
34 QObject::connect(m_dialog, SIGNAL(finished(int)),
35 this, SLOT(onFinished()));
36
37- QUrl webview("qrc:/MainWindow.qml");
38- QDir qmlDir("/usr/share/signon-ui/qml");
39- if (qmlDir.exists())
40- {
41- QFileInfo qmlFile(qmlDir.absolutePath() + "/MainWindow.qml");
42- if (qmlFile.exists())
43- webview.setUrl(qmlFile.absoluteFilePath());
44- }
45-
46+ m_dialog->engine()->addImportPath(PLUGIN_PRIVATE_MODULE_DIR);
47 m_dialog->rootContext()->setContextProperty("request", this);
48- m_dialog->rootContext()->setContextProperty("rootDir", m_rootDir);
49- m_dialog->setSource(webview);
50+ m_dialog->setSource(QUrl("qrc:/qml/SignOnUiPage.qml"));
51 } else {
52 DEBUG() << "Setting request on handler";
53 q->handler()->setRequest(this);
54@@ -208,7 +200,7 @@
55
56 void BrowserRequestPrivate::onLoadFinished(bool ok)
57 {
58- Q_Q(const BrowserRequest);
59+ Q_Q(BrowserRequest);
60
61 DEBUG() << "Load finished" << ok;
62
63@@ -219,9 +211,7 @@
64
65 if (m_dialog && !m_dialog->isVisible()) {
66 if (m_responseUrl.isEmpty()) {
67- Dialog::ShowMode mode =
68- (q->windowId() == 0) ? Dialog::TopLevel : Dialog::Transient;
69- m_dialog->show(q->windowId(), mode);
70+ q->setWindow(m_dialog);
71 } else {
72 onFinished();
73 }
74
75=== modified file 'src/module/OAuth.qml'
76--- src/module/OAuth.qml 2014-04-29 12:11:55 +0000
77+++ src/module/OAuth.qml 2014-08-11 13:15:20 +0000
78@@ -55,7 +55,6 @@
79 if (request) {
80 console.log("RequestHandler captured request!")
81 loader.setSource("WebView.qml", {
82- "rootDir": request.rootDir,
83 "signonRequest": request
84 })
85 } else {
86
87=== modified file 'src/module/WebView.qml'
88--- src/module/WebView.qml 2014-04-29 12:11:55 +0000
89+++ src/module/WebView.qml 2014-08-11 13:15:20 +0000
90@@ -5,7 +5,6 @@
91
92 UbuntuWebView {
93 property QtObject signonRequest
94- property url rootDir
95
96 Component.onCompleted: url = signonRequest.startUrl
97
98@@ -22,6 +21,6 @@
99 onUrlChanged: signonRequest.currentUrl = url
100
101 context: UbuntuWebContext {
102- dataPath: rootDir
103+ dataPath: signonRequest.rootDir
104 }
105 }
106
107=== modified file 'src/module/qmldir.in'
108--- src/module/qmldir.in 2013-06-05 11:33:39 +0000
109+++ src/module/qmldir.in 2014-08-11 13:15:20 +0000
110@@ -1,7 +1,9 @@
111 module $${API_URI}
112+KeyboardRectangle 1.0 KeyboardRectangle.qml
113 OAuthMain 1.0 OAuthMain.qml
114 OAuth 1.0 OAuth.qml
115 Options 1.0 Options.qml
116 RemovalConfirmation 1.0 RemovalConfirmation.qml
117 ServiceItem 1.0 ServiceItem.qml
118 ServiceSwitches 1.0 ServiceSwitches.qml
119+WebView 1.0 WebView.qml
120
121=== modified file 'src/notification.cpp'
122--- src/notification.cpp 2014-06-05 13:28:30 +0000
123+++ src/notification.cpp 2014-08-11 13:15:20 +0000
124@@ -108,6 +108,14 @@
125 this, NULL);
126 }
127
128+void Notification::setSnapDecision(bool snapDecision)
129+{
130+ Q_D(Notification);
131+ notify_notification_set_hint(d->m_notification,
132+ "x-canonical-snap-decisions",
133+ g_variant_new_boolean(snapDecision));
134+}
135+
136 void Notification::show()
137 {
138 Q_D(Notification);
139
140=== modified file 'src/notification.h'
141--- src/notification.h 2014-06-05 13:28:30 +0000
142+++ src/notification.h 2014-08-11 13:15:20 +0000
143@@ -37,6 +37,7 @@
144 ~Notification();
145
146 void addAction(const QString &action, const QString &label);
147+ void setSnapDecision(bool snapDecision);
148
149 public Q_SLOTS:
150 void show();
151
152=== modified file 'src/online-accounts-ui.pro'
153--- src/online-accounts-ui.pro 2014-06-05 13:28:30 +0000
154+++ src/online-accounts-ui.pro 2014-08-11 13:15:20 +0000
155@@ -92,7 +92,8 @@
156 qml/NormalStartupPage.qml \
157 qml/ProviderPluginList.qml \
158 qml/ProviderRequest.qml \
159- qml/ProvidersList.qml
160+ qml/ProvidersList.qml \
161+ qml/SignOnUiPage.qml
162
163 RESOURCES += \
164 ui.qrc
165
166=== added file 'src/qml/SignOnUiPage.qml'
167--- src/qml/SignOnUiPage.qml 1970-01-01 00:00:00 +0000
168+++ src/qml/SignOnUiPage.qml 2014-08-11 13:15:20 +0000
169@@ -0,0 +1,40 @@
170+import QtQuick 2.0
171+import Ubuntu.Components 0.1
172+import Ubuntu.Components.ListItems 0.1 as ListItem
173+import Ubuntu.OnlineAccounts.Plugin 1.0
174+
175+MainView {
176+ id: root
177+
178+ property var signonRequest: request
179+
180+ width: units.gu(60)
181+ height: units.gu(90)
182+
183+ Page {
184+ WebView {
185+ id: loader
186+ signonRequest: root.signonRequest
187+
188+ anchors {
189+ fill: parent
190+ bottomMargin: Math.max(osk.height, cancelButton.height)
191+ }
192+ }
193+
194+ ListItem.SingleControl {
195+ id: cancelButton
196+ anchors.bottom: parent.bottom
197+ showDivider: false
198+ control: Button {
199+ text: i18n.dtr("ubuntu-system-settings-online-accounts", "Cancel")
200+ width: parent.width - units.gu(4)
201+ onClicked: signonRequest.cancel()
202+ }
203+ }
204+
205+ KeyboardRectangle {
206+ id: osk
207+ }
208+ }
209+}
210
211=== modified file 'src/signonui-request.cpp'
212--- src/signonui-request.cpp 2014-06-05 13:28:30 +0000
213+++ src/signonui-request.cpp 2014-08-11 13:15:20 +0000
214@@ -1,7 +1,7 @@
215 /*
216 * This file is part of online-accounts-ui
217 *
218- * Copyright (C) 2011 Canonical Ltd.
219+ * Copyright (C) 2011-2014 Canonical Ltd.
220 *
221 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
222 *
223@@ -20,13 +20,16 @@
224
225 #include "signonui-request.h"
226
227+#include "account-manager.h"
228+#include "application-manager.h"
229 #include "browser-request.h"
230 #include "debug.h"
231 #include "globals.h"
232-#include "indicator-service.h"
233+#include "notification.h"
234
235 #include <Accounts/Account>
236-#include <Accounts/Manager>
237+#include <Accounts/Application>
238+#include <Accounts/Provider>
239 #include <QDBusArgument>
240 #include <SignOn/uisessiondata.h>
241 #include <SignOn/uisessiondata_priv.h>
242@@ -45,16 +48,19 @@
243 ~RequestPrivate();
244
245 private:
246- bool setWindow(QWindow *window);
247+ void setWindow(QWindow *window);
248 Accounts::Account *findAccount();
249- bool dispatchToIndicator();
250+
251+private Q_SLOTS:
252+ void onActionInvoked(const QString &action);
253+ void onNotificationClosed();
254
255 private:
256 mutable Request *q_ptr;
257 QVariantMap m_clientData;
258- bool m_inProgress;
259 RequestHandler *m_handler;
260- Accounts::Manager *m_accountManager;
261+ OnlineAccountsUi::Notification *m_notification;
262+ QWindow *m_window;
263 };
264
265 } // namespace
266@@ -62,9 +68,9 @@
267 RequestPrivate::RequestPrivate(Request *request):
268 QObject(request),
269 q_ptr(request),
270- m_inProgress(false),
271 m_handler(0),
272- m_accountManager(0)
273+ m_notification(0),
274+ m_window(0)
275 {
276 const QVariantMap &parameters = request->parameters();
277 if (parameters.contains(SSOUI_KEY_CLIENT_DATA)) {
278@@ -77,20 +83,51 @@
279
280 RequestPrivate::~RequestPrivate()
281 {
282+ delete m_notification;
283+ m_notification = 0;
284 }
285
286-bool RequestPrivate::setWindow(QWindow *window)
287+void RequestPrivate::setWindow(QWindow *window)
288 {
289 Q_Q(Request);
290- Q_UNUSED(window);
291
292- /* If the window has no parent and the webcredentials indicator service is
293- * up, dispatch the request to it. */
294- if (q->windowId() == 0 && dispatchToIndicator()) {
295- return true;
296+ /* Don't show the window yet: the user must be presented with a
297+ * snap-decision, and we'll show the window only if he decides to
298+ * authenticate. */
299+ Accounts::Account *account = findAccount();
300+ if (Q_UNLIKELY(!account)) {
301+ QVariantMap result;
302+ result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
303+ q->setResult(result);
304+ return;
305 }
306
307- return false;
308+ OnlineAccountsUi::ApplicationManager *appManager =
309+ OnlineAccountsUi::ApplicationManager::instance();
310+ Accounts::Application application =
311+ appManager->applicationFromProfile(q->clientApparmorProfile());
312+
313+ OnlineAccountsUi::AccountManager *accountManager =
314+ OnlineAccountsUi::AccountManager::instance();
315+ Accounts::Provider provider =
316+ accountManager->provider(account->providerName());
317+
318+ QString summary =
319+ QString("Please authorize %1 to access your %2 account %3").
320+ arg(application.isValid() ? application.displayName() : "Ubuntu").
321+ arg(provider.displayName()).
322+ arg(account->displayName());
323+ m_notification =
324+ new OnlineAccountsUi::Notification("Authentication request", summary);
325+ m_notification->addAction("cancel", "Cancel");
326+ m_notification->addAction("continue", "Authorize...");
327+ m_notification->setSnapDecision(true);
328+ QObject::connect(m_notification, SIGNAL(actionInvoked(const QString &)),
329+ this, SLOT(onActionInvoked(const QString &)));
330+ QObject::connect(m_notification, SIGNAL(closed()),
331+ this, SLOT(onNotificationClosed()));
332+ m_notification->show();
333+ m_window = window;
334 }
335
336 Accounts::Account *RequestPrivate::findAccount()
337@@ -104,11 +141,10 @@
338 /* Find the account using this identity.
339 * FIXME: there might be more than one!
340 */
341- if (m_accountManager == 0) {
342- m_accountManager = new Accounts::Manager(this);
343- }
344- Q_FOREACH(Accounts::AccountId accountId, m_accountManager->accountList()) {
345- Accounts::Account *account = m_accountManager->account(accountId);
346+ OnlineAccountsUi::AccountManager *manager =
347+ OnlineAccountsUi::AccountManager::instance();
348+ Q_FOREACH(Accounts::AccountId accountId, manager->accountList()) {
349+ Accounts::Account *account = manager->account(accountId);
350 if (account == 0) continue;
351
352 QVariant value(QVariant::UInt);
353@@ -122,34 +158,40 @@
354 return 0;
355 }
356
357-bool RequestPrivate::dispatchToIndicator()
358+void RequestPrivate::onActionInvoked(const QString &action)
359 {
360 Q_Q(Request);
361
362- Accounts::Account *account = findAccount();
363- if (account == 0) {
364- return false;
365+ DEBUG() << action;
366+
367+ QObject::disconnect(m_notification, 0, this, 0);
368+ m_notification->deleteLater();
369+ m_notification = 0;
370+
371+ if (action == QStringLiteral("continue")) {
372+ q->setWindow(m_window);
373+ } else {
374+ q->cancel();
375 }
376-
377- QVariantMap notification;
378- notification["DisplayName"] = account->displayName();
379- notification["ClientData"] = m_clientData;
380- notification["Identity"] = q->identity();
381- notification["Method"] = q->method();
382- notification["Mechanism"] = q->mechanism();
383-
384- IndicatorService *indicator = IndicatorService::instance();
385- indicator->reportFailure(account->id(), notification);
386-
387- /* the account has been reported as failing. We can now close this
388- * request, and tell the application that UI interaction is forbidden.
389- */
390+}
391+
392+void RequestPrivate::onNotificationClosed()
393+{
394+ Q_Q(Request);
395+
396+ DEBUG();
397+
398+ /* setResult() should have been called by onActionInvoked(), but calling it
399+ * twice won't harm because only the first invocation counts. */
400 QVariantMap result;
401 result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
402 q->setResult(result);
403- return true;
404+
405+ m_notification->deleteLater();
406+ m_notification = 0;
407 }
408
409+#ifndef NO_REQUEST_FACTORY
410 Request *Request::newRequest(const QDBusConnection &connection,
411 const QDBusMessage &message,
412 const QVariantMap &parameters,
413@@ -162,6 +204,7 @@
414 return 0; // TODO new DialogRequest(connection, message, parameters, parent);
415 }
416 }
417+#endif
418
419 Request::Request(const QDBusConnection &connection,
420 const QDBusMessage &message,
421@@ -189,8 +232,22 @@
422 void Request::setWindow(QWindow *window)
423 {
424 Q_D(Request);
425- if (!d->setWindow(window))
426+
427+ /* While a notification is shown, ignore any further calls to
428+ * setWindow(). */
429+ if (d->m_notification) return;
430+
431+ /* The first time that this method is called, we handle it by presenting a
432+ * snap decision to the user.
433+ * Then, if this is called again with the same QWindow, it means that the
434+ * snap decision was accepted, and we show the window.
435+ */
436+ if (window == d->m_window) {
437 OnlineAccountsUi::Request::setWindow(window);
438+ d->m_window = 0;
439+ } else {
440+ d->setWindow(window);
441+ }
442 }
443
444 uint Request::identity() const
445@@ -232,12 +289,10 @@
446
447 void Request::setCanceled()
448 {
449- if (isInProgress()) {
450- QVariantMap result;
451- result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_CANCELED;
452+ QVariantMap result;
453+ result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_CANCELED;
454
455- setResult(result);
456- }
457+ setResult(result);
458 }
459
460 #include "signonui-request.moc"
461
462=== modified file 'src/ui.qrc'
463--- src/ui.qrc 2014-03-19 12:14:14 +0000
464+++ src/ui.qrc 2014-08-11 13:15:20 +0000
465@@ -13,5 +13,6 @@
466 <file>qml/ProviderPluginList.qml</file>
467 <file>qml/ProviderRequest.qml</file>
468 <file>qml/ProvidersList.qml</file>
469+ <file>qml/SignOnUiPage.qml</file>
470 </qresource>
471 </RCC>
472
473=== added file 'system-settings-plugin/AccountEditPage.qml'
474--- system-settings-plugin/AccountEditPage.qml 1970-01-01 00:00:00 +0000
475+++ system-settings-plugin/AccountEditPage.qml 2014-08-11 13:15:20 +0000
476@@ -0,0 +1,66 @@
477+/*
478+ * Copyright (C) 2013 Canonical Ltd.
479+ *
480+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
481+ *
482+ * This program is free software: you can redistribute it and/or modify it
483+ * under the terms of the GNU General Public License version 3, as published
484+ * by the Free Software Foundation.
485+ *
486+ * This program is distributed in the hope that it will be useful, but
487+ * WITHOUT ANY WARRANTY; without even the implied warranties of
488+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
489+ * PURPOSE. See the GNU General Public License for more details.
490+ *
491+ * You should have received a copy of the GNU General Public License along
492+ * with this program. If not, see <http://www.gnu.org/licenses/>.
493+ */
494+
495+import QtQuick 2.0
496+import Ubuntu.Components 0.1
497+import Ubuntu.OnlineAccounts 0.1
498+
499+// HACK
500+import Ubuntu.OnlineAccounts.Plugin 1.0
501+
502+Page {
503+ id: root
504+
505+ property variant accountHandle
506+
507+ signal finished
508+
509+ title: account.provider.displayName
510+
511+ Account {
512+ id: account
513+ objectHandle: accountHandle
514+ }
515+
516+/* Loader {
517+ id: loader
518+ property var account: account
519+
520+ anchors.fill: parent
521+ source: localQmlPluginPath + account.provider.id + "/Main.qml"
522+
523+ onStatusChanged: {
524+ if (loader.status == Loader.Error) {
525+ loader.source = systemQmlPluginPath + account.provider.id + "/Main.qml"
526+ }
527+ }
528+
529+
530+ Connections {
531+ target: loader.item
532+ onFinished: {
533+ console.log("====== PLUGIN FINISHED ======")
534+ root.finished()
535+ }
536+ }
537+ }
538+*/
539+ // HACK: this only suppots OAuth-based providers...
540+ OAuthMain {}
541+
542+}
543
544=== added file 'system-settings-plugin/AccountItem.qml'
545--- system-settings-plugin/AccountItem.qml 1970-01-01 00:00:00 +0000
546+++ system-settings-plugin/AccountItem.qml 2014-08-11 13:15:20 +0000
547@@ -0,0 +1,59 @@
548+/*
549+ * Copyright (C) 2013 Canonical Ltd.
550+ *
551+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
552+ *
553+ * This program is free software: you can redistribute it and/or modify it
554+ * under the terms of the GNU General Public License version 3, as published
555+ * by the Free Software Foundation.
556+ *
557+ * This program is distributed in the hope that it will be useful, but
558+ * WITHOUT ANY WARRANTY; without even the implied warranties of
559+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
560+ * PURPOSE. See the GNU General Public License for more details.
561+ *
562+ * You should have received a copy of the GNU General Public License along
563+ * with this program. If not, see <http://www.gnu.org/licenses/>.
564+ */
565+
566+import QtQuick 2.0
567+import Ubuntu.Components 0.1
568+import Ubuntu.Components.ListItems 0.1 as ListItem
569+import Ubuntu.OnlineAccounts 0.1
570+
571+ListItem.Subtitled {
572+ property variant accountHandle
573+ property variant globalServiceHandle
574+ property variant __editPage: null
575+ property bool running: false
576+
577+ iconName: globalService.provider.iconName
578+ progression: true
579+ opacity: globalService.enabled ? 1 : 0.5
580+
581+ resources: [
582+ AccountService {
583+ id: globalService
584+ objectHandle: globalServiceHandle
585+ },
586+ Component {
587+ id: accountEditPage
588+ AccountEditPage {}
589+ }
590+ ]
591+
592+ onClicked: {
593+ __editPage = accountEditPage.createObject(null, {
594+ "accountHandle": accountHandle })
595+ __editPage.finished.connect(__onEditFinished)
596+ pageStack.push(__editPage)
597+ running = true;
598+ }
599+
600+ function __onEditFinished() {
601+ __editPage.destroy(1000)
602+ __editPage = null
603+ pageStack.pop()
604+ running = false
605+ }
606+}
607
608=== added file 'system-settings-plugin/AccountsPage.qml'
609--- system-settings-plugin/AccountsPage.qml 1970-01-01 00:00:00 +0000
610+++ system-settings-plugin/AccountsPage.qml 2014-08-11 13:15:20 +0000
611@@ -0,0 +1,65 @@
612+/*
613+ * Copyright (C) 2013 Canonical Ltd.
614+ *
615+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
616+ *
617+ * This program is free software: you can redistribute it and/or modify it
618+ * under the terms of the GNU General Public License version 3, as published
619+ * by the Free Software Foundation.
620+ *
621+ * This program is distributed in the hope that it will be useful, but
622+ * WITHOUT ANY WARRANTY; without even the implied warranties of
623+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
624+ * PURPOSE. See the GNU General Public License for more details.
625+ *
626+ * You should have received a copy of the GNU General Public License along
627+ * with this program. If not, see <http://www.gnu.org/licenses/>.
628+ */
629+
630+import QtQuick 2.0
631+import Ubuntu.Components 0.1
632+import Ubuntu.Components.ListItems 0.1 as ListItem
633+
634+Flickable {
635+ id: root
636+ property variant accountsModel
637+ contentHeight: contentItem.childrenRect.height
638+ boundsBehavior: Flickable.StopAtBounds
639+
640+ Column {
641+ anchors.left: parent.left
642+ anchors.right: parent.right
643+
644+ ListView {
645+ anchors.left: parent.left
646+ anchors.right: parent.right
647+ interactive: false
648+ height: contentHeight
649+ model: accountsModel
650+
651+ delegate: AccountItem {
652+ ListView.delayRemove: running
653+ text: providerName
654+ subText: displayName
655+ accountHandle: model.accountHandle
656+ globalServiceHandle: accountServiceHandle
657+ }
658+ }
659+
660+ ListItem.SingleControl {
661+ control: Button {
662+ text: i18n.tr("Add account…")
663+ width: parent.width - units.gu(4)
664+ onClicked: pageStack.push(newAccountPage)
665+ }
666+ showDivider: false
667+ }
668+
669+ AddAccountLabel {}
670+ }
671+
672+ Component {
673+ id: newAccountPage
674+ NewAccountPage {}
675+ }
676+}
677
678=== added file 'system-settings-plugin/AddAccountLabel.qml'
679--- system-settings-plugin/AddAccountLabel.qml 1970-01-01 00:00:00 +0000
680+++ system-settings-plugin/AddAccountLabel.qml 2014-08-11 13:15:20 +0000
681@@ -0,0 +1,28 @@
682+/*
683+ * Copyright (C) 2013 Canonical Ltd.
684+ *
685+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
686+ *
687+ * This program is free software: you can redistribute it and/or modify it
688+ * under the terms of the GNU General Public License version 3, as published
689+ * by the Free Software Foundation.
690+ *
691+ * This program is distributed in the hope that it will be useful, but
692+ * WITHOUT ANY WARRANTY; without even the implied warranties of
693+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
694+ * PURPOSE. See the GNU General Public License for more details.
695+ *
696+ * You should have received a copy of the GNU General Public License along
697+ * with this program. If not, see <http://www.gnu.org/licenses/>.
698+ */
699+
700+import QtQuick 2.0
701+import Ubuntu.Components 0.1
702+import Ubuntu.Components.ListItems 0.1 as ListItem
703+
704+ListItem.Caption {
705+ anchors.left: parent.left
706+ anchors.right: parent.right
707+ anchors.margins: units.gu(2)
708+ text: i18n.tr("Storing account details here lets apps use the accounts without you having to sign in for each app.")
709+}
710
711=== added file 'system-settings-plugin/AuthorizationPage.qml'
712--- system-settings-plugin/AuthorizationPage.qml 1970-01-01 00:00:00 +0000
713+++ system-settings-plugin/AuthorizationPage.qml 2014-08-11 13:15:20 +0000
714@@ -0,0 +1,75 @@
715+/*
716+ * Copyright (C) 2013 Canonical Ltd.
717+ *
718+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
719+ *
720+ * This program is free software: you can redistribute it and/or modify it
721+ * under the terms of the GNU General Public License version 3, as published
722+ * by the Free Software Foundation.
723+ *
724+ * This program is distributed in the hope that it will be useful, but
725+ * WITHOUT ANY WARRANTY; without even the implied warranties of
726+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
727+ * PURPOSE. See the GNU General Public License for more details.
728+ *
729+ * You should have received a copy of the GNU General Public License along
730+ * with this program. If not, see <http://www.gnu.org/licenses/>.
731+ */
732+
733+import QtQuick 2.0
734+import Ubuntu.Components 0.1
735+import Ubuntu.Components.ListItems 0.1 as ListItem
736+
737+Flickable {
738+ id: root
739+
740+ property variant model
741+ property variant application
742+ property variant provider
743+
744+ signal allowed(int accountId)
745+ signal denied
746+ signal createAccount
747+
748+ Column {
749+ anchors.left: parent.left
750+ anchors.right: parent.right
751+
752+ Label {
753+ anchors.left: parent.left
754+ anchors.right: parent.right
755+ text: i18n.tr("%1 wants to access your %2 account").
756+ arg(application.displayName).arg(provider.displayName);
757+ wrapMode: Text.WordWrap
758+ }
759+
760+ ListItem.ItemSelector {
761+ id: accountSelector
762+ anchors.left: parent.left
763+ anchors.right: parent.right
764+ text: "Account"
765+ model: root.model
766+ delegate: OptionSelectorDelegate {
767+ property string modelData: model.displayName
768+ }
769+ onDelegateClicked: {
770+ /* The last item in the model is the "Add another..." label */
771+ if (index == model.count - 1) root.createAccount();
772+ }
773+ }
774+
775+ Button {
776+ anchors.horizontalCenter: parent.horizontalCenter
777+ width: parent.width - units.gu(4)
778+ text: i18n.tr("Allow")
779+ onClicked: root.allowed(root.model.get(accountSelector.selectedIndex, "accountId"))
780+ }
781+
782+ Button {
783+ anchors.horizontalCenter: parent.horizontalCenter
784+ width: parent.width - units.gu(4)
785+ text: i18n.tr("Don't allow")
786+ onClicked: root.denied()
787+ }
788+ }
789+}
790
791=== added file 'system-settings-plugin/EntryComponent.qml'
792--- system-settings-plugin/EntryComponent.qml 1970-01-01 00:00:00 +0000
793+++ system-settings-plugin/EntryComponent.qml 2014-08-11 13:15:20 +0000
794@@ -0,0 +1,33 @@
795+/*
796+ * This file is part of system-settings
797+ *
798+ * Copyright (C) 2013 Canonical Ltd.
799+ *
800+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
801+ *
802+ * This program is free software: you can redistribute it and/or modify it
803+ * under the terms of the GNU General Public License version 3, as published
804+ * by the Free Software Foundation.
805+ *
806+ * This program is distributed in the hope that it will be useful, but
807+ * WITHOUT ANY WARRANTY; without even the implied warranties of
808+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
809+ * PURPOSE. See the GNU General Public License for more details.
810+ *
811+ * You should have received a copy of the GNU General Public License along
812+ * with this program. If not, see <http://www.gnu.org/licenses/>.
813+ */
814+
815+import QtQuick 2.0
816+import Ubuntu.Components 0.1
817+import Ubuntu.Components.ListItems 0.1 as ListItem
818+
819+ListItem.Standard {
820+ id: root
821+
822+ objectName: "entryComponent-about"
823+ iconSource: Qt.resolvedUrl(model.icon)
824+ iconFrame: false
825+ text: i18n.tr(model.displayName)
826+ progression: true
827+}
828
829=== added file 'system-settings-plugin/MainPage.qml'
830--- system-settings-plugin/MainPage.qml 1970-01-01 00:00:00 +0000
831+++ system-settings-plugin/MainPage.qml 2014-08-11 13:15:20 +0000
832@@ -0,0 +1,66 @@
833+/*
834+ * Copyright (C) 2013 Canonical Ltd.
835+ *
836+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
837+ *
838+ * This program is free software: you can redistribute it and/or modify it
839+ * under the terms of the GNU General Public License version 3, as published
840+ * by the Free Software Foundation.
841+ *
842+ * This program is distributed in the hope that it will be useful, but
843+ * WITHOUT ANY WARRANTY; without even the implied warranties of
844+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
845+ * PURPOSE. See the GNU General Public License for more details.
846+ *
847+ * You should have received a copy of the GNU General Public License along
848+ * with this program. If not, see <http://www.gnu.org/licenses/>.
849+ */
850+
851+import QtQuick 2.0
852+import SystemSettings 1.0
853+import Ubuntu.Components 0.1
854+import Ubuntu.Components.ListItems 0.1 as ListItem
855+import Ubuntu.OnlineAccounts 0.1
856+
857+ItemPage {
858+ id: root
859+ objectName: "accountsPage"
860+
861+ title: i18n.tr("Accounts")
862+
863+ // OnlineAccountsPanel {
864+ // id: onlineAccountsPanel
865+ // }
866+
867+ property Item flickable: accountsPage.visible ? accountsPage : noAccountsPage
868+
869+ AccountServiceModel {
870+ id: accountsModel
871+ service: "global"
872+ includeDisabled: true
873+ }
874+
875+ AccountsPage {
876+ id: accountsPage
877+ anchors.fill: parent
878+ accountsModel: accountsModel
879+ visible: accountsModel.count > 0
880+ }
881+
882+ NoAccountsPage {
883+ id: noAccountsPage
884+ anchors.fill: parent
885+ accountsModel: accountsModel
886+ visible:!accountsPage.visible
887+ }
888+
889+
890+ Component {
891+ id: accountCreationPage
892+ AccountCreationPage {
893+ providerId: pluginOptions.provider
894+ }
895+ }
896+
897+}
898+
899
900=== added file 'system-settings-plugin/NewAccountPage.qml'
901--- system-settings-plugin/NewAccountPage.qml 1970-01-01 00:00:00 +0000
902+++ system-settings-plugin/NewAccountPage.qml 2014-08-11 13:15:20 +0000
903@@ -0,0 +1,38 @@
904+/*
905+ * Copyright (C) 2013 Canonical Ltd.
906+ *
907+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
908+ *
909+ * This program is free software: you can redistribute it and/or modify it
910+ * under the terms of the GNU General Public License version 3, as published
911+ * by the Free Software Foundation.
912+ *
913+ * This program is distributed in the hope that it will be useful, but
914+ * WITHOUT ANY WARRANTY; without even the implied warranties of
915+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
916+ * PURPOSE. See the GNU General Public License for more details.
917+ *
918+ * You should have received a copy of the GNU General Public License along
919+ * with this program. If not, see <http://www.gnu.org/licenses/>.
920+ */
921+
922+import QtQuick 2.0
923+import Ubuntu.Components 0.1
924+
925+Page {
926+ title: i18n.tr("Add account")
927+
928+ Flickable {
929+ anchors.fill: parent
930+ contentHeight: contentItem.childrenRect.height
931+ boundsBehavior: Flickable.StopAtBounds
932+
933+ ProviderPluginList {
934+ onCreationFinished: {
935+ // pop the creation page and this page (go back to parent page)
936+ pageStack.pop()
937+ pageStack.pop()
938+ }
939+ }
940+ }
941+}
942
943=== added file 'system-settings-plugin/NoAccountsPage.qml'
944--- system-settings-plugin/NoAccountsPage.qml 1970-01-01 00:00:00 +0000
945+++ system-settings-plugin/NoAccountsPage.qml 2014-08-11 13:15:20 +0000
946@@ -0,0 +1,54 @@
947+/*
948+ * Copyright (C) 2013 Canonical Ltd.
949+ *
950+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
951+ *
952+ * This program is free software: you can redistribute it and/or modify it
953+ * under the terms of the GNU General Public License version 3, as published
954+ * by the Free Software Foundation.
955+ *
956+ * This program is distributed in the hope that it will be useful, but
957+ * WITHOUT ANY WARRANTY; without even the implied warranties of
958+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
959+ * PURPOSE. See the GNU General Public License for more details.
960+ *
961+ * You should have received a copy of the GNU General Public License along
962+ * with this program. If not, see <http://www.gnu.org/licenses/>.
963+ */
964+
965+import QtQuick 2.0
966+import Ubuntu.Components 0.1
967+import Ubuntu.Components.ListItems 0.1 as ListItem
968+
969+Flickable {
970+ id: root
971+
972+ property variant accountsModel
973+ contentHeight: contentItem.childrenRect.height
974+ boundsBehavior: Flickable.StopAtBounds
975+
976+ Column {
977+ anchors.left: parent.left
978+ anchors.right: parent.right
979+
980+ ListItem.Base {
981+ Label {
982+ text: i18n.tr("No accounts")
983+ anchors.centerIn: parent
984+ }
985+ }
986+
987+ AddAccountLabel {}
988+
989+ ListItem.Standard {
990+ text: i18n.tr("Add account:")
991+ }
992+
993+ ProviderPluginList {
994+ onCreationFinished: {
995+ // pop the creation page; remain in this page
996+ pageStack.pop()
997+ }
998+ }
999+ }
1000+}
1001
1002=== added file 'system-settings-plugin/NormalStartupPage.qml'
1003--- system-settings-plugin/NormalStartupPage.qml 1970-01-01 00:00:00 +0000
1004+++ system-settings-plugin/NormalStartupPage.qml 2014-08-11 13:15:20 +0000
1005@@ -0,0 +1,46 @@
1006+/*
1007+ * Copyright (C) 2013 Canonical Ltd.
1008+ *
1009+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1010+ *
1011+ * This program is free software: you can redistribute it and/or modify it
1012+ * under the terms of the GNU General Public License version 3, as published
1013+ * by the Free Software Foundation.
1014+ *
1015+ * This program is distributed in the hope that it will be useful, but
1016+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1017+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1018+ * PURPOSE. See the GNU General Public License for more details.
1019+ *
1020+ * You should have received a copy of the GNU General Public License along
1021+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1022+ */
1023+
1024+import QtQuick 2.0
1025+import Ubuntu.OnlineAccounts 0.1
1026+
1027+Item {
1028+ id: root
1029+
1030+ property Item flickable: accountsPage.visible ? accountsPage : noAccountsPage
1031+
1032+ AccountServiceModel {
1033+ id: accountsModel
1034+ service: "global"
1035+ includeDisabled: true
1036+ }
1037+
1038+ AccountsPage {
1039+ id: accountsPage
1040+ anchors.fill: parent
1041+ accountsModel: accountsModel
1042+ visible: accountsModel.count > 0
1043+ }
1044+
1045+ NoAccountsPage {
1046+ id: noAccountsPage
1047+ anchors.fill: parent
1048+ accountsModel: accountsModel
1049+ visible: !accountsPage.visible
1050+ }
1051+}
1052
1053=== added file 'system-settings-plugin/ProviderPluginList.qml'
1054--- system-settings-plugin/ProviderPluginList.qml 1970-01-01 00:00:00 +0000
1055+++ system-settings-plugin/ProviderPluginList.qml 2014-08-11 13:15:20 +0000
1056@@ -0,0 +1,42 @@
1057+/*
1058+ * Copyright (C) 2013 Canonical Ltd.
1059+ *
1060+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1061+ *
1062+ * This program is free software: you can redistribute it and/or modify it
1063+ * under the terms of the GNU General Public License version 3, as published
1064+ * by the Free Software Foundation.
1065+ *
1066+ * This program is distributed in the hope that it will be useful, but
1067+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1068+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1069+ * PURPOSE. See the GNU General Public License for more details.
1070+ *
1071+ * You should have received a copy of the GNU General Public License along
1072+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1073+ */
1074+
1075+import QtQuick 2.0
1076+import Ubuntu.Components 0.1
1077+
1078+ProvidersList {
1079+ id: root
1080+
1081+ property variant __creationPage: null
1082+
1083+ signal creationFinished
1084+
1085+ onProviderClicked: {
1086+ __creationPage = accountCreationPage.createObject(null, {
1087+ "providerId": providerId })
1088+ __creationPage.finished.connect(__onCreationFinished)
1089+ pageStack.push(__creationPage)
1090+ }
1091+
1092+ function __onCreationFinished() {
1093+ __creationPage.destroy(1000)
1094+ __creationPage.finished.disconnect(__onCreationFinished)
1095+ __creationPage = null
1096+ creationFinished()
1097+ }
1098+}
1099
1100=== added file 'system-settings-plugin/ProvidersList.qml'
1101--- system-settings-plugin/ProvidersList.qml 1970-01-01 00:00:00 +0000
1102+++ system-settings-plugin/ProvidersList.qml 2014-08-11 13:15:20 +0000
1103@@ -0,0 +1,62 @@
1104+/*
1105+ * Copyright (C) 2013 Canonical Ltd.
1106+ *
1107+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1108+ *
1109+ * This program is free software: you can redistribute it and/or modify it
1110+ * under the terms of the GNU General Public License version 3, as published
1111+ * by the Free Software Foundation.
1112+ *
1113+ * This program is distributed in the hope that it will be useful, but
1114+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1115+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1116+ * PURPOSE. See the GNU General Public License for more details.
1117+ *
1118+ * You should have received a copy of the GNU General Public License along
1119+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1120+ */
1121+
1122+import QtQuick 2.0
1123+import Ubuntu.Components 0.1
1124+import Ubuntu.Components.ListItems 0.1 as ListItem
1125+import Ubuntu.OnlineAccounts 0.1
1126+
1127+Column {
1128+ id: root
1129+
1130+ signal providerClicked(string providerId)
1131+
1132+ anchors.left: parent.left
1133+ anchors.right: parent.right
1134+
1135+ ProviderModel {
1136+ id: providerModel
1137+ }
1138+
1139+ Repeater {
1140+ model: providerModel
1141+
1142+ delegate: ListItem.Standard {
1143+ text: displayName
1144+ enabled: !isSingleAccount || hasNoAccounts(providerId)
1145+ iconName: model.iconName
1146+ progression: true
1147+ onClicked: root.providerClicked(providerId)
1148+ }
1149+ }
1150+
1151+ Component {
1152+ id: accountModel
1153+ AccountServiceModel {
1154+ includeDisabled: true
1155+ }
1156+ }
1157+
1158+ function hasNoAccounts(providerId) {
1159+ var model = accountModel.createObject(null, {
1160+ "provider": providerId })
1161+ var hasAccounts = (model.count > 0)
1162+ model.destroy()
1163+ return !hasAccounts
1164+ }
1165+}
1166
1167=== modified file 'system-settings-plugin/online-accounts.settings'
1168--- system-settings-plugin/online-accounts.settings 2013-09-09 10:56:53 +0000
1169+++ system-settings-plugin/online-accounts.settings 2014-08-11 13:15:20 +0000
1170@@ -11,5 +11,6 @@
1171 ],
1172 "has-dynamic-keywords": true,
1173 "has-dynamic-visibility": false,
1174- "plugin": "online-accounts"
1175+ "entry-component": "EntryComponent.qml",
1176+ "page-component": "MainPage.qml"
1177 }
1178
1179=== modified file 'system-settings-plugin/plugin.cpp'
1180--- system-settings-plugin/plugin.cpp 2014-05-30 08:55:40 +0000
1181+++ system-settings-plugin/plugin.cpp 2014-08-11 13:15:20 +0000
1182@@ -16,74 +16,21 @@
1183 * with this program. If not, see <http://www.gnu.org/licenses/>.
1184 */
1185
1186+#include <QtQml>
1187+#include <QtQml/QQmlContext>
1188 #include "plugin.h"
1189-
1190-#include <OnlineAccountsClient/Setup>
1191-#include <QDebug>
1192-#include <QStringList>
1193-#include <SystemSettings/ItemBase>
1194-
1195-using namespace SystemSettings;
1196-
1197-class Item: public ItemBase
1198-{
1199- Q_OBJECT
1200-
1201-public:
1202- Item(const QVariantMap &staticData, QObject *parent = 0);
1203- ~Item();
1204-
1205- QQmlComponent *pageComponent(QQmlEngine *engine,
1206- QObject *parent = 0) Q_DECL_OVERRIDE;
1207-
1208-private Q_SLOTS:
1209- void onFinished();
1210-
1211-private:
1212- OnlineAccountsClient::Setup m_setup;
1213- bool m_isOpen;
1214-};
1215-
1216-Item::Item(const QVariantMap &staticData, QObject *parent):
1217- ItemBase(staticData, parent),
1218- m_isOpen(false)
1219-{
1220- QObject::connect(&m_setup, SIGNAL(finished()),
1221- this, SLOT(onFinished()));
1222-}
1223-
1224-Item::~Item()
1225-{
1226-}
1227-
1228-QQmlComponent *Item::pageComponent(QQmlEngine *engine,
1229- QObject *parent)
1230-{
1231- Q_UNUSED(engine);
1232- Q_UNUSED(parent);
1233-
1234- if (!m_isOpen) {
1235- qDebug() << "Opening Online Accounts";
1236- m_isOpen = true;
1237- m_setup.exec();
1238- }
1239- return 0;
1240-}
1241-
1242-void Item::onFinished()
1243-{
1244- m_isOpen = false;
1245-}
1246-
1247-Plugin::Plugin():
1248- QObject()
1249-{
1250-}
1251-
1252-ItemBase *Plugin::createItem(const QVariantMap &staticData,
1253- QObject *parent)
1254-{
1255- return new Item(staticData, parent);
1256-}
1257-
1258-#include "plugin.moc"
1259+// #include "accounts.h"
1260+
1261+
1262+void BackendPlugin::registerTypes(const char *uri)
1263+{
1264+ Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.OnlineAccounts"));
1265+
1266+ qDebug() << uri;
1267+ // qmlRegisterType<OnlineAccounts>(uri, 1, 0, "OnlineAccountsPanel");
1268+}
1269+
1270+void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
1271+{
1272+ QQmlExtensionPlugin::initializeEngine(engine, uri);
1273+}
1274
1275=== modified file 'system-settings-plugin/plugin.h'
1276--- system-settings-plugin/plugin.h 2013-09-09 10:56:53 +0000
1277+++ system-settings-plugin/plugin.h 2014-08-11 13:15:20 +0000
1278@@ -19,20 +19,17 @@
1279 #ifndef ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
1280 #define ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
1281
1282-#include <QObject>
1283-#include <SystemSettings/PluginInterface>
1284+#include <QtQml/QQmlEngine>
1285+#include <QtQml/QQmlExtensionPlugin>
1286
1287-class Plugin: public QObject, public SystemSettings::PluginInterface
1288+class BackendPlugin : public QQmlExtensionPlugin
1289 {
1290 Q_OBJECT
1291- Q_PLUGIN_METADATA(IID "com.ubuntu.SystemSettings.PluginInterface")
1292- Q_INTERFACES(SystemSettings::PluginInterface)
1293+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
1294
1295 public:
1296- Plugin();
1297-
1298- SystemSettings::ItemBase *createItem(const QVariantMap &staticData,
1299- QObject *parent = 0);
1300+ void registerTypes(const char *uri);
1301+ void initializeEngine(QQmlEngine *engine, const char *uri);
1302 };
1303
1304 #endif // ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
1305
1306=== modified file 'system-settings-plugin/system-settings-plugin.pro'
1307--- system-settings-plugin/system-settings-plugin.pro 2013-09-09 10:56:53 +0000
1308+++ system-settings-plugin/system-settings-plugin.pro 2014-08-11 13:15:20 +0000
1309@@ -4,6 +4,21 @@
1310 TEMPLATE = lib
1311 TARGET = online-accounts
1312
1313+QML_SOURCES = \
1314+ AccountEditPage.qml \
1315+ AccountCreationPage.qml \
1316+ AuthorizationPage.qml \
1317+ NoAccountsPage.qml \
1318+ AccountItem.qml \
1319+ EntryComponent.qml \
1320+ NormalStartupPage.qml \
1321+ AccountsPage.qml \
1322+ MainPage.qml \
1323+ ProviderPluginList.qml \
1324+ AddAccountLabel.qml \
1325+ NewAccountPage.qml \
1326+ ProvidersList.qml
1327+
1328 CONFIG += \
1329 link_pkgconfig \
1330 plugin \
1331@@ -39,3 +54,6 @@
1332 image.path = $${PLUGIN_MANIFEST_DIR}/icons
1333 INSTALLS += image
1334
1335+qml.files = $${QML_SOURCES}
1336+qml.path = $${PLUGIN_QML_DIR}/online-accounts
1337+INSTALLS += qml
1338
1339=== added file 'tests/online-accounts-ui/data/com.ubuntu.tests_application.application'
1340--- tests/online-accounts-ui/data/com.ubuntu.tests_application.application 1970-01-01 00:00:00 +0000
1341+++ tests/online-accounts-ui/data/com.ubuntu.tests_application.application 2014-08-11 13:15:20 +0000
1342@@ -0,0 +1,19 @@
1343+<?xml version="1.0" encoding="UTF-8" ?>
1344+<application id="com.ubuntu.tests_application">
1345+ <description>Mailer</description>
1346+ <translations>mailer-catalog</translations>
1347+ <desktop-entry>mailer.desktop</desktop-entry>
1348+
1349+ <service-types>
1350+ <service-type id="e-mail">
1351+ <description>Mailer can retrieve your e-mails</description>
1352+ </service-type>
1353+ </service-types>
1354+
1355+ <services>
1356+ <service id="coolshare">
1357+ <description>Mailer can even share stuff on CoolShare</description>
1358+ </service>
1359+ </services>
1360+ <profile>com.ubuntu.tests_application_0.3</profile>
1361+</application>
1362
1363=== added file 'tests/online-accounts-ui/mock/notification-mock.cpp'
1364--- tests/online-accounts-ui/mock/notification-mock.cpp 1970-01-01 00:00:00 +0000
1365+++ tests/online-accounts-ui/mock/notification-mock.cpp 2014-08-11 13:15:20 +0000
1366@@ -0,0 +1,81 @@
1367+/*
1368+ * Copyright (C) 2014 Canonical Ltd.
1369+ *
1370+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1371+ *
1372+ * This file is part of online-accounts-ui
1373+ *
1374+ * This program is free software: you can redistribute it and/or modify it
1375+ * under the terms of the GNU General Public License version 3, as published
1376+ * by the Free Software Foundation.
1377+ *
1378+ * This program is distributed in the hope that it will be useful, but
1379+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1380+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1381+ * PURPOSE. See the GNU General Public License for more details.
1382+ *
1383+ * You should have received a copy of the GNU General Public License along
1384+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1385+ */
1386+
1387+#include "notification-mock.h"
1388+
1389+#include <QByteArray>
1390+#include <QDebug>
1391+#include <QString>
1392+
1393+using namespace OnlineAccountsUi;
1394+
1395+QList<Notification*> NotificationPrivate::allNotifications;
1396+
1397+NotificationPrivate::NotificationPrivate(const QString &summary,
1398+ const QString &body,
1399+ Notification *notification):
1400+ QObject(notification),
1401+ m_summary(summary),
1402+ m_body(body),
1403+ q_ptr(notification)
1404+{
1405+ allNotifications.append(notification);
1406+}
1407+
1408+NotificationPrivate::~NotificationPrivate()
1409+{
1410+ allNotifications.removeAll(q_ptr);
1411+}
1412+
1413+void NotificationPrivate::invokeAction(const QString &action)
1414+{
1415+ Q_Q(Notification);
1416+ Q_EMIT q->actionInvoked(action);
1417+}
1418+
1419+Notification::Notification(const QString &summary,
1420+ const QString &body,
1421+ QObject *parent):
1422+ QObject(parent),
1423+ d_ptr(new NotificationPrivate(summary, body, this))
1424+{
1425+}
1426+
1427+Notification::~Notification()
1428+{
1429+}
1430+
1431+void Notification::addAction(const QString &action, const QString &label)
1432+{
1433+ Q_D(Notification);
1434+ d->m_actions.append(ActionPair(action, label));
1435+}
1436+
1437+void Notification::setSnapDecision(bool snapDecision)
1438+{
1439+ Q_D(Notification);
1440+ d->m_isSnapDecision = snapDecision;
1441+}
1442+
1443+void Notification::show()
1444+{
1445+ Q_D(Notification);
1446+ Q_EMIT d->showCalled();
1447+}
1448
1449=== added file 'tests/online-accounts-ui/mock/notification-mock.h'
1450--- tests/online-accounts-ui/mock/notification-mock.h 1970-01-01 00:00:00 +0000
1451+++ tests/online-accounts-ui/mock/notification-mock.h 2014-08-11 13:15:20 +0000
1452@@ -0,0 +1,66 @@
1453+/*
1454+ * Copyright (C) 2014 Canonical Ltd.
1455+ *
1456+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1457+ *
1458+ * This file is part of online-accounts-ui
1459+ *
1460+ * This program is free software: you can redistribute it and/or modify it
1461+ * under the terms of the GNU General Public License version 3, as published
1462+ * by the Free Software Foundation.
1463+ *
1464+ * This program is distributed in the hope that it will be useful, but
1465+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1466+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1467+ * PURPOSE. See the GNU General Public License for more details.
1468+ *
1469+ * You should have received a copy of the GNU General Public License along
1470+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1471+ */
1472+
1473+#ifndef MOCK_NOTIFICATiON_H
1474+#define MOCK_NOTIFICATiON_H
1475+
1476+#include "notification.h"
1477+
1478+#include <QByteArray>
1479+#include <QList>
1480+#include <QPair>
1481+#include <QString>
1482+
1483+using namespace OnlineAccountsUi;
1484+
1485+namespace OnlineAccountsUi {
1486+
1487+typedef QPair<QString,QString> ActionPair;
1488+
1489+class NotificationPrivate: public QObject
1490+{
1491+ Q_OBJECT
1492+ Q_DECLARE_PUBLIC(Notification)
1493+
1494+public:
1495+ NotificationPrivate(const QString &summary,
1496+ const QString &body,
1497+ Notification *notification);
1498+ ~NotificationPrivate();
1499+ static NotificationPrivate *mocked(Notification *n) { return n->d_ptr; }
1500+
1501+ static QList<Notification *> allNotifications;
1502+
1503+ void invokeAction(const QString &action);
1504+
1505+Q_SIGNALS:
1506+ void showCalled();
1507+
1508+public:
1509+ QString m_summary;
1510+ QString m_body;
1511+ QList<ActionPair> m_actions;
1512+ bool m_isSnapDecision;
1513+ mutable Notification *q_ptr;
1514+};
1515+
1516+} // namespace
1517+
1518+#endif // MOCK_NOTIFICATiON_H
1519
1520=== added file 'tests/online-accounts-ui/mock/request-mock.cpp'
1521--- tests/online-accounts-ui/mock/request-mock.cpp 1970-01-01 00:00:00 +0000
1522+++ tests/online-accounts-ui/mock/request-mock.cpp 2014-08-11 13:15:20 +0000
1523@@ -0,0 +1,136 @@
1524+/*
1525+ * Copyright (C) 2014 Canonical Ltd.
1526+ *
1527+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1528+ *
1529+ * This file is part of online-accounts-ui
1530+ *
1531+ * This program is free software: you can redistribute it and/or modify it
1532+ * under the terms of the GNU General Public License version 3, as published
1533+ * by the Free Software Foundation.
1534+ *
1535+ * This program is distributed in the hope that it will be useful, but
1536+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1537+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1538+ * PURPOSE. See the GNU General Public License for more details.
1539+ *
1540+ * You should have received a copy of the GNU General Public License along
1541+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1542+ */
1543+
1544+#include "globals.h"
1545+#include "request-mock.h"
1546+
1547+#include <QDebug>
1548+
1549+using namespace OnlineAccountsUi;
1550+
1551+RequestPrivate::RequestPrivate(const QDBusConnection &connection,
1552+ const QDBusMessage &message,
1553+ const QVariantMap &parameters,
1554+ Request *request):
1555+ QObject(request),
1556+ q_ptr(request),
1557+ m_parameters(parameters),
1558+ m_window(0),
1559+ m_inProgress(false)
1560+{
1561+ Q_UNUSED(connection);
1562+ Q_UNUSED(message);
1563+}
1564+
1565+RequestPrivate::~RequestPrivate()
1566+{
1567+}
1568+
1569+Request::Request(const QDBusConnection &connection,
1570+ const QDBusMessage &message,
1571+ const QVariantMap &parameters,
1572+ QObject *parent):
1573+ QObject(parent),
1574+ d_ptr(new RequestPrivate(connection, message, parameters, this))
1575+{
1576+}
1577+
1578+Request::~Request()
1579+{
1580+}
1581+
1582+void Request::setWindow(QWindow *window)
1583+{
1584+ Q_D(Request);
1585+ Q_EMIT d->setWindowCalled(window);
1586+}
1587+
1588+WId Request::windowId() const
1589+{
1590+ Q_D(const Request);
1591+ return d->m_parameters[OAU_KEY_WINDOW_ID].toUInt();
1592+}
1593+
1594+bool Request::isInProgress() const
1595+{
1596+ Q_D(const Request);
1597+ return d->m_inProgress;
1598+}
1599+
1600+const QVariantMap &Request::parameters() const
1601+{
1602+ Q_D(const Request);
1603+ return d->m_parameters;
1604+}
1605+
1606+QString Request::clientApparmorProfile() const
1607+{
1608+ Q_D(const Request);
1609+ return d->m_clientApparmorProfile;
1610+}
1611+
1612+QWindow *Request::window() const
1613+{
1614+ Q_D(const Request);
1615+ return d->m_window;
1616+}
1617+
1618+void Request::start()
1619+{
1620+ Q_D(Request);
1621+ if (d->m_inProgress) {
1622+ qWarning() << "Request already started!";
1623+ return;
1624+ }
1625+ d->m_inProgress = true;
1626+}
1627+
1628+void Request::cancel()
1629+{
1630+ setCanceled();
1631+}
1632+
1633+void Request::fail(const QString &name, const QString &message)
1634+{
1635+ Q_D(Request);
1636+ Q_EMIT d->failCalled(name, message);
1637+
1638+ Q_EMIT completed();
1639+}
1640+
1641+void Request::setCanceled()
1642+{
1643+ Q_D(Request);
1644+ if (d->m_inProgress) {
1645+ fail(OAU_ERROR_USER_CANCELED, QStringLiteral("Canceled"));
1646+ d->m_inProgress = false;
1647+ }
1648+}
1649+
1650+void Request::setResult(const QVariantMap &result)
1651+{
1652+ Q_D(Request);
1653+ if (d->m_inProgress) {
1654+ Q_EMIT d->setResultCalled(result);
1655+
1656+ Q_EMIT completed();
1657+ d->m_inProgress = false;
1658+ }
1659+}
1660
1661=== added file 'tests/online-accounts-ui/mock/request-mock.h'
1662--- tests/online-accounts-ui/mock/request-mock.h 1970-01-01 00:00:00 +0000
1663+++ tests/online-accounts-ui/mock/request-mock.h 2014-08-11 13:15:20 +0000
1664@@ -0,0 +1,64 @@
1665+/*
1666+ * Copyright (C) 2014 Canonical Ltd.
1667+ *
1668+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1669+ *
1670+ * This file is part of online-accounts-ui
1671+ *
1672+ * This program is free software: you can redistribute it and/or modify it
1673+ * under the terms of the GNU General Public License version 3, as published
1674+ * by the Free Software Foundation.
1675+ *
1676+ * This program is distributed in the hope that it will be useful, but
1677+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1678+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1679+ * PURPOSE. See the GNU General Public License for more details.
1680+ *
1681+ * You should have received a copy of the GNU General Public License along
1682+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1683+ */
1684+
1685+#ifndef MOCK_REQUEST_H
1686+#define MOCK_REQUEST_H
1687+
1688+#include "request.h"
1689+
1690+#include <QObject>
1691+#include <QString>
1692+#include <QVariantMap>
1693+
1694+namespace OnlineAccountsUi {
1695+
1696+class RequestPrivate: public QObject
1697+{
1698+ Q_OBJECT
1699+ Q_DECLARE_PUBLIC(Request)
1700+
1701+public:
1702+ RequestPrivate(const QDBusConnection &connection,
1703+ const QDBusMessage &message,
1704+ const QVariantMap &parameters,
1705+ Request *request);
1706+ ~RequestPrivate();
1707+ static RequestPrivate *mocked(Request *r) { return r->d_ptr; }
1708+
1709+ void setClientApparmorProfile(const QString &profile) {
1710+ m_clientApparmorProfile = profile;
1711+ }
1712+
1713+Q_SIGNALS:
1714+ void setWindowCalled(QWindow *);
1715+ void failCalled(const QString &name, const QString &message);
1716+ void setResultCalled(const QVariantMap &result);
1717+
1718+private:
1719+ mutable Request *q_ptr;
1720+ QVariantMap m_parameters;
1721+ QString m_clientApparmorProfile;
1722+ QWindow *m_window;
1723+ bool m_inProgress;
1724+};
1725+
1726+} // namespace
1727+
1728+#endif // MOCK_REQUEST_H
1729
1730=== modified file 'tests/online-accounts-ui/online-accounts-ui.pro'
1731--- tests/online-accounts-ui/online-accounts-ui.pro 2014-06-05 13:28:30 +0000
1732+++ tests/online-accounts-ui/online-accounts-ui.pro 2014-08-11 13:15:20 +0000
1733@@ -5,4 +5,5 @@
1734 tst_application_manager.pro \
1735 tst_inactivity_timer.pro \
1736 tst_notification.pro \
1737- tst_service.pro
1738+ tst_service.pro \
1739+ tst_signonui_request.pro
1740
1741=== modified file 'tests/online-accounts-ui/tst_notification.cpp'
1742--- tests/online-accounts-ui/tst_notification.cpp 2014-06-05 13:28:30 +0000
1743+++ tests/online-accounts-ui/tst_notification.cpp 2014-08-11 13:15:20 +0000
1744@@ -26,6 +26,7 @@
1745 #include <QPair>
1746 #include <QSignalSpy>
1747 #include <QTest>
1748+#include <QVariantMap>
1749 #include <libnotify/notification.h>
1750 #include <libnotify/notify.h>
1751
1752@@ -52,6 +53,7 @@
1753 QString summary;
1754 QString body;
1755 QList<ActionPair> actions;
1756+ QVariantMap hints;
1757 bool visible;
1758
1759 MockNotification();
1760@@ -167,6 +169,22 @@
1761 callbackData.userData = user_data;
1762 }
1763
1764+void notify_notification_set_hint(NotifyNotification *notification,
1765+ const char *key,
1766+ GVariant *value)
1767+{
1768+ MockNotification *mock =
1769+ reinterpret_cast<MockNotification*>(notification);
1770+ QVariant variant;
1771+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
1772+ variant = bool(g_variant_get_boolean(value));
1773+ } else {
1774+ /* Add support for any needed types */
1775+ qWarning() << "Unsupported variant type";
1776+ }
1777+ mock->hints.insert(QString::fromUtf8(key), variant);
1778+}
1779+
1780 /* End of mock code */
1781
1782 class NotificationTest: public QObject
1783@@ -180,6 +198,7 @@
1784 void testInitialization();
1785 void testDestruction();
1786 void testContents();
1787+ void testSnapDecision();
1788 void testVisibility();
1789 void testClosing();
1790 void testActions();
1791@@ -220,6 +239,20 @@
1792 MockNotification *mock = *(notifications.begin());
1793 QCOMPARE(mock->summary, QString("Summary"));
1794 QCOMPARE(mock->body, QString("Body"));
1795+ QVERIFY(mock->hints.isEmpty());
1796+}
1797+
1798+void NotificationTest::testSnapDecision()
1799+{
1800+ Notification first("Summary", "Body");
1801+ MockNotification *mock = *(notifications.begin());
1802+ QVERIFY(mock->hints.isEmpty());
1803+
1804+ first.setSnapDecision(true);
1805+ QCOMPARE(mock->hints["x-canonical-snap-decisions"].toBool(), true);
1806+
1807+ first.setSnapDecision(false);
1808+ QCOMPARE(mock->hints["x-canonical-snap-decisions"].toBool(), false);
1809 }
1810
1811 void NotificationTest::testVisibility()
1812
1813=== added file 'tests/online-accounts-ui/tst_signonui_request.cpp'
1814--- tests/online-accounts-ui/tst_signonui_request.cpp 1970-01-01 00:00:00 +0000
1815+++ tests/online-accounts-ui/tst_signonui_request.cpp 2014-08-11 13:15:20 +0000
1816@@ -0,0 +1,338 @@
1817+/*
1818+ * Copyright (C) 2014 Canonical Ltd.
1819+ *
1820+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1821+ *
1822+ * This file is part of online-accounts-ui
1823+ *
1824+ * This program is free software: you can redistribute it and/or modify it
1825+ * under the terms of the GNU General Public License version 3, as published
1826+ * by the Free Software Foundation.
1827+ *
1828+ * This program is distributed in the hope that it will be useful, but
1829+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1830+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1831+ * PURPOSE. See the GNU General Public License for more details.
1832+ *
1833+ * You should have received a copy of the GNU General Public License along
1834+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1835+ */
1836+
1837+#include "globals.h"
1838+#include "request-handler.h"
1839+#include "signonui-request.h"
1840+#include "mock/notification-mock.h"
1841+#include "mock/request-mock.h"
1842+
1843+#include <Accounts/Account>
1844+#include <Accounts/Manager>
1845+
1846+#include <QDebug>
1847+#include <QSignalSpy>
1848+#include <QTemporaryDir>
1849+#include <QTest>
1850+
1851+#include <SignOn/uisessiondata.h>
1852+#include <SignOn/uisessiondata_priv.h>
1853+
1854+using namespace OnlineAccountsUi;
1855+
1856+class TestRequest: public SignOnUi::Request
1857+{
1858+ Q_OBJECT
1859+
1860+public:
1861+ TestRequest(const QDBusConnection &connection,
1862+ const QDBusMessage &message,
1863+ const QVariantMap &parameters,
1864+ QObject *parent = 0):
1865+ Request(connection, message, parameters, parent)
1866+ {
1867+ }
1868+
1869+ void setWindow(QWindow *window) { Request::setWindow(window); }
1870+
1871+ void sendResult(const QVariantMap &result) { setResult(result); }
1872+};
1873+
1874+class SignonuiRequestTest: public QObject
1875+{
1876+ Q_OBJECT
1877+
1878+public:
1879+ SignonuiRequestTest();
1880+
1881+private Q_SLOTS:
1882+ void initTestCase();
1883+ void testParameters_data();
1884+ void testParameters();
1885+ void testHandler();
1886+ void testSnapDecision_data();
1887+ void testSnapDecision();
1888+
1889+private:
1890+ bool mustCreateAccount(uint credentialsId) { return credentialsId > 10; }
1891+
1892+private:
1893+ QDBusConnection m_connection;
1894+ QDBusMessage m_message;
1895+ QTemporaryDir m_accountsDir;
1896+};
1897+
1898+SignonuiRequestTest::SignonuiRequestTest():
1899+ QObject(),
1900+ m_connection(QStringLiteral("uninitialized"))
1901+{
1902+}
1903+
1904+void SignonuiRequestTest::initTestCase()
1905+{
1906+ QVERIFY(m_accountsDir.isValid());
1907+
1908+ qputenv("ACCOUNTS", m_accountsDir.path().toUtf8());
1909+ qputenv("AG_APPLICATIONS", TEST_DATA_DIR);
1910+ qputenv("AG_PROVIDERS", TEST_DATA_DIR);
1911+ qputenv("AG_SERVICES", TEST_DATA_DIR);
1912+ qputenv("XDG_DATA_HOME", TEST_DATA_DIR);
1913+}
1914+
1915+void SignonuiRequestTest::testParameters_data()
1916+{
1917+ QTest::addColumn<QVariantMap>("parameters");
1918+ QTest::addColumn<uint>("identity");
1919+ QTest::addColumn<QString>("method");
1920+ QTest::addColumn<QString>("mechanism");
1921+ QTest::addColumn<QString>("id");
1922+ QTest::addColumn<QVariantMap>("clientData");
1923+
1924+ QTest::newRow("empty") <<
1925+ QVariantMap() <<
1926+ uint(0) <<
1927+ QString() <<
1928+ QString() <<
1929+ QString() <<
1930+ QVariantMap();
1931+
1932+ QVariantMap clientData;
1933+ clientData.insert("some number", 4);
1934+
1935+ QVariantMap parameters;
1936+ parameters.insert(SSOUI_KEY_CLIENT_DATA, clientData);
1937+ parameters.insert(SSOUI_KEY_IDENTITY, uint(45));
1938+ parameters.insert(SSOUI_KEY_METHOD, QString("a method"));
1939+ parameters.insert(SSOUI_KEY_MECHANISM, QString("a mechanism"));
1940+ parameters.insert(SSOUI_KEY_REQUESTID, QString("/id-4"));
1941+
1942+
1943+ QTest::newRow("basic") <<
1944+ parameters <<
1945+ uint(45) <<
1946+ "a method" <<
1947+ "a mechanism" <<
1948+ "/id-4" <<
1949+ clientData;
1950+}
1951+
1952+void SignonuiRequestTest::testParameters()
1953+{
1954+ QFETCH(QVariantMap, parameters);
1955+ QFETCH(QString, method);
1956+ QFETCH(QString, mechanism);
1957+ QFETCH(QString, id);
1958+ QFETCH(QVariantMap, clientData);
1959+
1960+ TestRequest request(m_connection, m_message, parameters);
1961+ QCOMPARE(request.method(), method);
1962+ QCOMPARE(request.mechanism(), mechanism);
1963+ QCOMPARE(request.id(), id);
1964+ QCOMPARE(request.clientData(), clientData);
1965+}
1966+
1967+void SignonuiRequestTest::testHandler()
1968+{
1969+ QVariantMap parameters;
1970+ TestRequest request(m_connection, m_message, parameters);
1971+ QVERIFY(request.handler() == 0);
1972+
1973+ SignOnUi::RequestHandler *handler = new SignOnUi::RequestHandler;
1974+ request.setHandler(handler);
1975+ QCOMPARE(request.handler(), handler);
1976+
1977+ /* Try to set another handler; this won't be allowed */
1978+ SignOnUi::RequestHandler *handler2 = new SignOnUi::RequestHandler;
1979+ request.setHandler(handler2);
1980+ QCOMPARE(request.handler(), handler);
1981+
1982+ delete handler2;
1983+ delete handler;
1984+}
1985+
1986+void SignonuiRequestTest::testSnapDecision_data()
1987+{
1988+ QTest::addColumn<uint>("credentialsId");
1989+ QTest::addColumn<QString>("accountName");
1990+ QTest::addColumn<QString>("clientProfile");
1991+ QTest::addColumn<QString>("applicationName");
1992+ QTest::addColumn<bool>("mustAccept");
1993+ QTest::addColumn<QVariantMap>("result");
1994+
1995+ QVariantMap acceptedResult;
1996+ acceptedResult.insert("some key", QString("some value"));
1997+
1998+ QVariantMap declinedResult;
1999+ declinedResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_CANCELED);
2000+
2001+ QVariantMap errorResult;
2002+ errorResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_FORBIDDEN);
2003+
2004+ QTest::newRow("no account") <<
2005+ uint(0) <<
2006+ "tom@example.com" <<
2007+ "com.ubuntu.tests_application_0.3" <<
2008+ QString() <<
2009+ false <<
2010+ errorResult;
2011+
2012+ QTest::newRow("invalid account") <<
2013+ uint(1) <<
2014+ "tom@example.com" <<
2015+ "com.ubuntu.tests_application_0.3" <<
2016+ QString() <<
2017+ false <<
2018+ errorResult;
2019+
2020+ QTest::newRow("valid application, accepted") <<
2021+ uint(14231) <<
2022+ "tom@example.com" <<
2023+ "com.ubuntu.tests_application_0.3" <<
2024+ "Easy Mailer" <<
2025+ true <<
2026+ acceptedResult;
2027+
2028+ QTest::newRow("valid application, declined") <<
2029+ uint(14231) <<
2030+ "tom@example.com" <<
2031+ "com.ubuntu.tests_application_0.3" <<
2032+ "Easy Mailer" <<
2033+ false <<
2034+ declinedResult;
2035+
2036+ QTest::newRow("unconfined application, accepted") <<
2037+ uint(14235) <<
2038+ "tom@example.com" <<
2039+ "unconfined" <<
2040+ "Ubuntu" <<
2041+ true <<
2042+ acceptedResult;
2043+
2044+ QTest::newRow("unconfined application, declined") <<
2045+ uint(14235) <<
2046+ "tom@example.com" <<
2047+ "unconfined" <<
2048+ "Ubuntu" <<
2049+ false <<
2050+ declinedResult;
2051+}
2052+
2053+void SignonuiRequestTest::testSnapDecision()
2054+{
2055+ QString providerId("cool");
2056+ QFETCH(uint, credentialsId);
2057+ QFETCH(QString, accountName);
2058+ QFETCH(QString, clientProfile);
2059+ QFETCH(QString, applicationName);
2060+ QFETCH(bool, mustAccept);
2061+ QFETCH(QVariantMap, result);
2062+
2063+ // First, create an account
2064+ Accounts::Manager *manager = new Accounts::Manager(this);
2065+ Accounts::Provider provider = manager->provider(providerId);
2066+ QVERIFY(provider.isValid());
2067+ if (mustCreateAccount(credentialsId)) {
2068+ Accounts::Account *account = manager->createAccount(providerId);
2069+ QVERIFY(account != 0);
2070+ account->setEnabled(true);
2071+ account->setDisplayName(accountName);
2072+ account->setCredentialsId(credentialsId);
2073+ account->syncAndBlock();
2074+ }
2075+
2076+ /* Then, create a request referring to the same credentials ID of the
2077+ * created account. */
2078+ QVariantMap parameters;
2079+ parameters.insert(SSOUI_KEY_IDENTITY, credentialsId);
2080+ parameters.insert(SSOUI_KEY_METHOD, "funnyMethod");
2081+ parameters.insert(SSOUI_KEY_MECHANISM, "funnyMechanism");
2082+ TestRequest request(m_connection, m_message, parameters);
2083+ OnlineAccountsUi::RequestPrivate *mockRequest =
2084+ OnlineAccountsUi::RequestPrivate::mocked(&request);
2085+ QSignalSpy failCalled(mockRequest,
2086+ SIGNAL(failCalled(const QString&, const QString&)));
2087+ QSignalSpy setResultCalled(mockRequest,
2088+ SIGNAL(setResultCalled(const QVariantMap &)));
2089+ mockRequest->setClientApparmorProfile(clientProfile);
2090+ request.start();
2091+
2092+ /* Request to show a window; a snap decision should appear instead */
2093+ QWindow *window = new QWindow;
2094+ QSignalSpy setWindowCalled(mockRequest,
2095+ SIGNAL(setWindowCalled(QWindow*)));
2096+ request.setWindow(window);
2097+ QCOMPARE(setWindowCalled.count(), 0);
2098+ if (mustCreateAccount(credentialsId)) {
2099+ QCOMPARE(NotificationPrivate::allNotifications.count(), 1);
2100+ } else {
2101+ /* If the account is not found, no notification should appear, and an
2102+ * error returned to the app */
2103+ QCOMPARE(NotificationPrivate::allNotifications.count(), 0);
2104+ QCOMPARE(setResultCalled.count(), 1);
2105+ QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
2106+ return;
2107+ }
2108+
2109+ /* Inspect the snap decision contents */
2110+ Notification *notification =
2111+ NotificationPrivate::allNotifications.first();
2112+ NotificationPrivate *mockNotification =
2113+ NotificationPrivate::mocked(notification);
2114+ QCOMPARE(mockNotification->m_summary, QString("Authentication request"));
2115+ QCOMPARE(mockNotification->m_body,
2116+ QString("Please authorize %1 to access your %2 account %3").
2117+ arg(applicationName).arg(provider.displayName()).arg(accountName));
2118+ QVERIFY(mockNotification->m_isSnapDecision);
2119+
2120+ /* Invoke the action on the snap decision */
2121+ QString action = mustAccept ? "continue" : "cancel";
2122+ QSignalSpy actionInvoked(notification,
2123+ SIGNAL(actionInvoked(const QString &)));
2124+ mockNotification->invokeAction(action);
2125+ QCOMPARE(actionInvoked.count(), 1);
2126+ QCOMPARE(actionInvoked.at(0).at(0).toString(), action);
2127+
2128+ /* Here we iterate the main loop because the notification object is
2129+ * destroyed with deleteLater() */
2130+ QTest::qWait(5);
2131+
2132+ if (mustAccept) {
2133+ QCOMPARE(setWindowCalled.count(), 1);
2134+ QCOMPARE(setWindowCalled.at(0).at(0), QVariant::fromValue(window));
2135+ QCOMPARE(failCalled.count(), 0);
2136+ QCOMPARE(setResultCalled.count(), 0);
2137+
2138+ /* deliver the result */
2139+ request.sendResult(result);
2140+ QCOMPARE(setResultCalled.count(), 1);
2141+ QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
2142+ } else {
2143+ QCOMPARE(setWindowCalled.count(), 0);
2144+ QCOMPARE(failCalled.count(), 0);
2145+ QCOMPARE(setResultCalled.count(), 1);
2146+ QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
2147+ }
2148+ delete window;
2149+ delete manager;
2150+}
2151+
2152+QTEST_MAIN(SignonuiRequestTest);
2153+
2154+#include "tst_signonui_request.moc"
2155
2156=== added file 'tests/online-accounts-ui/tst_signonui_request.pro'
2157--- tests/online-accounts-ui/tst_signonui_request.pro 1970-01-01 00:00:00 +0000
2158+++ tests/online-accounts-ui/tst_signonui_request.pro 2014-08-11 13:15:20 +0000
2159@@ -0,0 +1,53 @@
2160+include(../../common-project-config.pri)
2161+
2162+TARGET = tst_signonui_request
2163+
2164+CONFIG += \
2165+ debug \
2166+ link_pkgconfig
2167+
2168+QT += \
2169+ core \
2170+ dbus \
2171+ testlib
2172+
2173+PKGCONFIG += \
2174+ accounts-qt5 \
2175+ libsignon-qt5 \
2176+ signon-plugins-common
2177+
2178+DEFINES += \
2179+ DEBUG_ENABLED \
2180+ NO_REQUEST_FACTORY \
2181+ TEST_DATA_DIR=\\\"$${PWD}/data\\\"
2182+
2183+SRCDIR = $${TOP_SRC_DIR}/src
2184+
2185+SOURCES += \
2186+ $${SRCDIR}/account-manager.cpp \
2187+ $${SRCDIR}/application-manager.cpp \
2188+ $${SRCDIR}/debug.cpp \
2189+ $${SRCDIR}/request-handler.cpp \
2190+ $${SRCDIR}/signonui-request.cpp \
2191+ mock/notification-mock.cpp \
2192+ mock/request-mock.cpp \
2193+ mock/qwindow.cpp \
2194+ tst_signonui_request.cpp
2195+
2196+HEADERS += \
2197+ $${SRCDIR}/account-manager.h \
2198+ $${SRCDIR}/application-manager.h \
2199+ $${SRCDIR}/notification.h \
2200+ $${SRCDIR}/request.h \
2201+ $${SRCDIR}/request-handler.h \
2202+ $${SRCDIR}/signonui-request.h \
2203+ mock/notification-mock.h \
2204+ mock/request-mock.h \
2205+ window-watcher.h
2206+
2207+INCLUDEPATH += \
2208+ $${SRCDIR}
2209+
2210+check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
2211+check.depends = $${TARGET}
2212+QMAKE_EXTRA_TARGETS += check

Subscribers

People subscribed via source and target branches