diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-application.hook ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-application.hook --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-application.hook 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-application.hook 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,2 @@ +User-Level: yes +Pattern: ${home}/.local/share/accounts/applications/${id}.application diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-provider.hook ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-provider.hook --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-provider.hook 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-provider.hook 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,2 @@ +Pattern: ${home}/.local/share/accounts/providers/${short-id}.provider +User-Level: yes diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-qml-plugin.hook ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-qml-plugin.hook --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-qml-plugin.hook 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-qml-plugin.hook 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,2 @@ +Pattern: ${home}/.local/share/accounts/qml-plugins/${short-id} +User-Level: yes diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-service.hook ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-service.hook --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/account-service.hook 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/account-service.hook 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,2 @@ +Pattern: ${home}/.local/share/accounts/services/${short-id}.service +User-Level: yes diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/click-hooks.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/click-hooks.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/click-hooks/click-hooks.pro 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/click-hooks/click-hooks.pro 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,11 @@ +include(../common-project-config.pri) + +TEMPLATE = aux + +hooks.files = \ + account-application.hook \ + account-provider.hook \ + account-qml-plugin.hook \ + account-service.hook +hooks.path = $${INSTALL_PREFIX}/share/click/hooks +INSTALLS += hooks diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/debian/changelog ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/debian/changelog --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/debian/changelog 2014-03-13 18:46:27.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/debian/changelog 2014-03-13 18:46:27.000000000 +0000 @@ -1,3 +1,9 @@ +ubuntu-system-settings-online-accounts (0.3+14.04.20140307.1-0ubuntu1) trusty; urgency=low + + * New rebuild forced + + -- Ubuntu daily release Fri, 07 Mar 2014 08:37:17 +0000 + ubuntu-system-settings-online-accounts (0.3+14.04.20140304.is.0.2~+14.04.20131205-0ubuntu1) trusty; urgency=medium * Reverting as desktop image isn't installable (main/universe diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ast.po ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ast.po --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ast.po 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ast.po 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,86 @@ +# Asturian translation for ubuntu-system-settings-online-accounts +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the ubuntu-system-settings-online-accounts package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: ubuntu-system-settings-online-accounts\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2013-07-10 19:34+0200\n" +"PO-Revision-Date: 2014-02-06 20:02+0000\n" +"Last-Translator: Xuacu Saturio \n" +"Language-Team: Asturian \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-02-07 07:17+0000\n" +"X-Generator: Launchpad (build 16916)\n" + +#: ../plugins/example/Main.qml:33 +msgid "User name" +msgstr "Nome d'usuariu" + +#: ../plugins/example/Main.qml:39 +msgid "Password" +msgstr "Contraseña" + +#: ../src/AccountsPage.qml:53 +msgid "Add account…" +msgstr "Amestar cuenta…" + +#: ../src/AddAccountLabel.qml:27 +msgid "" +"Storing account details here lets apps use the accounts without you having " +"to sign in for each app." +msgstr "" +"Guardar equí la información de la cuenta permitirá que les aplicaciones la " +"usen ensin tener qu'aniciar sesión con caúna d'elles." + +#: ../src/NewAccountPage.qml:23 +msgid "Add account" +msgstr "Amestar cuenta" + +#: ../src/NoAccountsPage.qml:36 +msgid "No accounts" +msgstr "Nun hai cuentes" + +#: ../src/NoAccountsPage.qml:44 +msgid "Add account:" +msgstr "Amestar cuenta:" + +#: ../src/module/OAuth.qml:82 ../src/module/RemovalConfirmation.qml:41 +msgid "Cancel" +msgstr "Encaboxar" + +#: ../src/module/Options.qml:36 +msgid "ID" +msgstr "ID" + +#: ../src/module/Options.qml:54 +msgid "Remove account…" +msgstr "Desaniciar cuenta..." + +#: ../src/module/RemovalConfirmation.qml:32 +msgid "Remove account" +msgstr "Desaniciar cuenta" + +#: ../src/module/RemovalConfirmation.qml:33 +#, qt-format +msgid "" +"The %1 account will be removed only from your phone. You can add it again " +"later." +msgstr "" +"La cuenta %1 desaniciaráse sólo del teléfonu. Pue volver a amestala más sero." + +#: ../src/module/RemovalConfirmation.qml:36 +msgid "Remove" +msgstr "Desaniciar" + +#: ../src/module/ServiceSwitches.qml:33 +msgid "Access to this account:" +msgstr "Entrar a esta cuenta:" + +#: ../.build/settings.js:1 +msgid "Accounts" +msgstr "Cuentes" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/br.po ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/br.po --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/br.po 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/br.po 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,87 @@ +# Breton translation for ubuntu-system-settings-online-accounts +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the ubuntu-system-settings-online-accounts package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: ubuntu-system-settings-online-accounts\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2013-07-10 19:34+0200\n" +"PO-Revision-Date: 2014-03-06 07:27+0000\n" +"Last-Translator: Fohanno Thierry \n" +"Language-Team: Breton \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-03-07 07:30+0000\n" +"X-Generator: Launchpad (build 16948)\n" + +#: ../plugins/example/Main.qml:33 +msgid "User name" +msgstr "Anv implijer" + +#: ../plugins/example/Main.qml:39 +msgid "Password" +msgstr "Ger-tremen" + +#: ../src/AccountsPage.qml:53 +msgid "Add account…" +msgstr "Ouzhpennañ ur gont…" + +#: ../src/AddAccountLabel.qml:27 +msgid "" +"Storing account details here lets apps use the accounts without you having " +"to sign in for each app." +msgstr "" +"Mirout munudoù ar gont amañ a lezo an arloadoù da ober gant ar c'hontoù hep " +"goulenn diganeoc'h en em gevreañ evit pep arload." + +#: ../src/NewAccountPage.qml:23 +msgid "Add account" +msgstr "Ouzhpennañ ur gont" + +#: ../src/NoAccountsPage.qml:36 +msgid "No accounts" +msgstr "Kont ebet" + +#: ../src/NoAccountsPage.qml:44 +msgid "Add account:" +msgstr "Ouzhpennañ ur gont :" + +#: ../src/module/OAuth.qml:82 ../src/module/RemovalConfirmation.qml:41 +msgid "Cancel" +msgstr "Nullañ" + +#: ../src/module/Options.qml:36 +msgid "ID" +msgstr "ID" + +#: ../src/module/Options.qml:54 +msgid "Remove account…" +msgstr "Dilemel ar gont..." + +#: ../src/module/RemovalConfirmation.qml:32 +msgid "Remove account" +msgstr "Dilemel ar gont" + +#: ../src/module/RemovalConfirmation.qml:33 +#, qt-format +msgid "" +"The %1 account will be removed only from your phone. You can add it again " +"later." +msgstr "" +"Ar gont %1 a vo lamet kuit diwar ho pellgomzer nemetken. Gallout a reoc'h " +"adlakaat anezhi diwezhatoc'h." + +#: ../src/module/RemovalConfirmation.qml:36 +msgid "Remove" +msgstr "Dilemel" + +#: ../src/module/ServiceSwitches.qml:33 +msgid "Access to this account:" +msgstr "Mont d'ar gont-mañ :" + +#: ../.build/settings.js:1 +msgid "Accounts" +msgstr "Kontoù" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ckb.po ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ckb.po --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ckb.po 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ckb.po 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,83 @@ +# Kurdish (Sorani) translation for ubuntu-system-settings-online-accounts +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the ubuntu-system-settings-online-accounts package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: ubuntu-system-settings-online-accounts\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2013-07-10 19:34+0200\n" +"PO-Revision-Date: 2014-01-19 11:35+0000\n" +"Last-Translator: FULL NAME \n" +"Language-Team: Kurdish (Sorani) \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-01-20 06:02+0000\n" +"X-Generator: Launchpad (build 16901)\n" + +#: ../plugins/example/Main.qml:33 +msgid "User name" +msgstr "" + +#: ../plugins/example/Main.qml:39 +msgid "Password" +msgstr "" + +#: ../src/AccountsPage.qml:53 +msgid "Add account…" +msgstr "" + +#: ../src/AddAccountLabel.qml:27 +msgid "" +"Storing account details here lets apps use the accounts without you having " +"to sign in for each app." +msgstr "" + +#: ../src/NewAccountPage.qml:23 +msgid "Add account" +msgstr "" + +#: ../src/NoAccountsPage.qml:36 +msgid "No accounts" +msgstr "" + +#: ../src/NoAccountsPage.qml:44 +msgid "Add account:" +msgstr "" + +#: ../src/module/OAuth.qml:82 ../src/module/RemovalConfirmation.qml:41 +msgid "Cancel" +msgstr "" + +#: ../src/module/Options.qml:36 +msgid "ID" +msgstr "" + +#: ../src/module/Options.qml:54 +msgid "Remove account…" +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:32 +msgid "Remove account" +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:33 +#, qt-format +msgid "" +"The %1 account will be removed only from your phone. You can add it again " +"later." +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:36 +msgid "Remove" +msgstr "" + +#: ../src/module/ServiceSwitches.qml:33 +msgid "Access to this account:" +msgstr "" + +#: ../.build/settings.js:1 +msgid "Accounts" +msgstr "" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/fa.po ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/fa.po --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/fa.po 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/fa.po 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,83 @@ +# Persian translation for ubuntu-system-settings-online-accounts +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the ubuntu-system-settings-online-accounts package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: ubuntu-system-settings-online-accounts\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2013-07-10 19:34+0200\n" +"PO-Revision-Date: 2014-01-16 17:23+0000\n" +"Last-Translator: FULL NAME \n" +"Language-Team: Persian \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-01-17 07:08+0000\n" +"X-Generator: Launchpad (build 16901)\n" + +#: ../plugins/example/Main.qml:33 +msgid "User name" +msgstr "" + +#: ../plugins/example/Main.qml:39 +msgid "Password" +msgstr "" + +#: ../src/AccountsPage.qml:53 +msgid "Add account…" +msgstr "" + +#: ../src/AddAccountLabel.qml:27 +msgid "" +"Storing account details here lets apps use the accounts without you having " +"to sign in for each app." +msgstr "" + +#: ../src/NewAccountPage.qml:23 +msgid "Add account" +msgstr "" + +#: ../src/NoAccountsPage.qml:36 +msgid "No accounts" +msgstr "" + +#: ../src/NoAccountsPage.qml:44 +msgid "Add account:" +msgstr "" + +#: ../src/module/OAuth.qml:82 ../src/module/RemovalConfirmation.qml:41 +msgid "Cancel" +msgstr "" + +#: ../src/module/Options.qml:36 +msgid "ID" +msgstr "" + +#: ../src/module/Options.qml:54 +msgid "Remove account…" +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:32 +msgid "Remove account" +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:33 +#, qt-format +msgid "" +"The %1 account will be removed only from your phone. You can add it again " +"later." +msgstr "" + +#: ../src/module/RemovalConfirmation.qml:36 +msgid "Remove" +msgstr "" + +#: ../src/module/ServiceSwitches.qml:33 +msgid "Access to this account:" +msgstr "" + +#: ../.build/settings.js:1 +msgid "Accounts" +msgstr "" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ms.po ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ms.po --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/po/ms.po 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/po/ms.po 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,87 @@ +# Malay translation for ubuntu-system-settings-online-accounts +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the ubuntu-system-settings-online-accounts package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: ubuntu-system-settings-online-accounts\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2013-07-10 19:34+0200\n" +"PO-Revision-Date: 2014-01-17 09:17+0000\n" +"Last-Translator: abuyop \n" +"Language-Team: Malay \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-01-18 07:10+0000\n" +"X-Generator: Launchpad (build 16901)\n" + +#: ../plugins/example/Main.qml:33 +msgid "User name" +msgstr "Nama pengguna" + +#: ../plugins/example/Main.qml:39 +msgid "Password" +msgstr "Kata laluan" + +#: ../src/AccountsPage.qml:53 +msgid "Add account…" +msgstr "Tambah akaun..." + +#: ../src/AddAccountLabel.qml:27 +msgid "" +"Storing account details here lets apps use the accounts without you having " +"to sign in for each app." +msgstr "" +"Menyimpan perincian akaun di sini membolehkan apl guna akaun tanpa perlu " +"anda mendaftar masuk untuk setiap apl." + +#: ../src/NewAccountPage.qml:23 +msgid "Add account" +msgstr "Tambah akaun" + +#: ../src/NoAccountsPage.qml:36 +msgid "No accounts" +msgstr "Tiada akaun" + +#: ../src/NoAccountsPage.qml:44 +msgid "Add account:" +msgstr "Tambah akaun:" + +#: ../src/module/OAuth.qml:82 ../src/module/RemovalConfirmation.qml:41 +msgid "Cancel" +msgstr "Batal" + +#: ../src/module/Options.qml:36 +msgid "ID" +msgstr "ID" + +#: ../src/module/Options.qml:54 +msgid "Remove account…" +msgstr "Buang akaun..." + +#: ../src/module/RemovalConfirmation.qml:32 +msgid "Remove account" +msgstr "Buang akaun" + +#: ../src/module/RemovalConfirmation.qml:33 +#, qt-format +msgid "" +"The %1 account will be removed only from your phone. You can add it again " +"later." +msgstr "" +"Akaun %1 akan hanya dibuang dari telefon anda. Anda boleh tambah ia kemudian " +"nanti." + +#: ../src/module/RemovalConfirmation.qml:36 +msgid "Remove" +msgstr "Buang" + +#: ../src/module/ServiceSwitches.qml:33 +msgid "Access to this account:" +msgstr "Capai ke akaun ini:" + +#: ../.build/settings.js:1 +msgid "Accounts" +msgstr "Akaun" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/access-model.cpp ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/access-model.cpp --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/access-model.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/access-model.cpp 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "access-model.h" +#include "account-manager.h" +#include "debug.h" + +#include +#include +#include +#include + +using namespace OnlineAccountsUi; + +namespace OnlineAccountsUi { + +class AccessModelPrivate: public QSortFilterProxyModel +{ + Q_OBJECT + Q_DECLARE_PUBLIC(AccessModel) + +public: + inline AccessModelPrivate(AccessModel *accessModel); + inline ~AccessModelPrivate(); + + void ensureSupportedServices() const; + +protected: + bool filterAcceptsRow(int source_row, + const QModelIndex &source_parent) const Q_DECL_OVERRIDE; + +private: + mutable AccessModel *q_ptr; + mutable Accounts::ServiceList m_supportedServices; + QString m_lastItemText; + QString m_applicationId; +}; + +} // namespace + +AccessModelPrivate::AccessModelPrivate(AccessModel *accessModel): + QSortFilterProxyModel(accessModel), + q_ptr(accessModel) +{ +} + +AccessModelPrivate::~AccessModelPrivate() +{ +} + +void AccessModelPrivate::ensureSupportedServices() const +{ + if (!m_supportedServices.isEmpty()) return; // Nothing to do + + /* List all services supported by the accounts's provider. We know that the + * account model is an instance of the accounts-qml-module's + * AccountServiceModel, and that its "provider" property must be set. */ + QAbstractItemModel *accountModel = sourceModel(); + if (!accountModel) return; + + QString providerId = accountModel->property("provider").toString(); + if (providerId.isEmpty()) return; + + AccountManager *manager = AccountManager::instance(); + Accounts::Application application = manager->application(m_applicationId); + Accounts::ServiceList allServices = manager->serviceList(); + Q_FOREACH(const Accounts::Service &service, allServices) { + if (service.provider() == providerId && + !application.serviceUsage(service).isEmpty()) { + m_supportedServices.append(service); + } + } +} + +bool AccessModelPrivate::filterAcceptsRow(int sourceRow, + const QModelIndex &sourceParent) const +{ + Q_UNUSED(sourceParent); + + if (m_applicationId.isEmpty()) return true; + + /* We must avoid showing those accounts which have already been enabled for + * this application. */ + ensureSupportedServices(); + QVariant result; + bool ok = QMetaObject::invokeMethod(sourceModel(), "get", + Qt::DirectConnection, + Q_RETURN_ARG(QVariant, result), + Q_ARG(int, sourceRow), + Q_ARG(QString, "accountHandle")); + if (Q_UNLIKELY(!ok)) return false; + + QObject *accountHandle = result.value(); + Accounts::Account *account = + qobject_cast(accountHandle); + if (Q_UNLIKELY(!account)) return false; + + bool allServicesEnabled = true; + Q_FOREACH(const Accounts::Service &service, m_supportedServices) { + account->selectService(service); + if (!account->isEnabled()) { + allServicesEnabled = false; + break; + } + } + + DEBUG() << account->id() << "allServicesEnabled" << allServicesEnabled; + return !allServicesEnabled; +} + +AccessModel::AccessModel(QObject *parent): + QIdentityProxyModel(parent), + d_ptr(new AccessModelPrivate(this)) +{ + Q_D(AccessModel); + + QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex&,int,int)), + this, SIGNAL(countChanged())); + QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), + this, SIGNAL(countChanged())); + d->setDynamicSortFilter(true); + setSourceModel(d); +} + +AccessModel::~AccessModel() +{ +} + +void AccessModel::setAccountModel(QAbstractItemModel *accountModel) +{ + Q_D(AccessModel); + + d->setSourceModel(accountModel); + Q_EMIT accountModelChanged(); +} + +QAbstractItemModel *AccessModel::accountModel() const +{ + Q_D(const AccessModel); + return d->sourceModel(); +} + +int AccessModel::rowCount(const QModelIndex &parent) const +{ + return QIdentityProxyModel::rowCount(parent) + 1; +} + +void AccessModel::setLastItemText(const QString &text) +{ + Q_D(AccessModel); + + if (text == d->m_lastItemText) return; + d->m_lastItemText = text; + Q_EMIT lastItemTextChanged(); + + QModelIndex lastItemIndex = index(d->rowCount(), 0); + Q_EMIT dataChanged(lastItemIndex, lastItemIndex); +} + +QString AccessModel::lastItemText() const +{ + Q_D(const AccessModel); + return d->m_lastItemText; +} + +void AccessModel::setApplicationId(const QString &applicationId) +{ + Q_D(AccessModel); + + if (applicationId == d->m_applicationId) return; + d->m_applicationId = applicationId; + Q_EMIT applicationIdChanged(); + + d->m_supportedServices.clear(); + /* Trigger a refresh of the filtered model */ + d->invalidateFilter(); +} + +QString AccessModel::applicationId() const +{ + Q_D(const AccessModel); + return d->m_applicationId; +} + +QVariant AccessModel::get(int row, const QString &roleName) const +{ + int role = roleNames().key(roleName.toLatin1(), -1); + return data(index(row, 0), role); +} + +QVariant AccessModel::data(const QModelIndex &index, int role) const +{ + Q_D(const AccessModel); + int row = index.row(); + if (row < d->rowCount()) { + return QIdentityProxyModel::data(index, role); + } else { + if (Q_UNLIKELY(row > d->rowCount())) return QVariant(); + return d->m_lastItemText; + } +} + +QHash AccessModel::roleNames() const +{ + Q_D(const AccessModel); + return d->roleNames(); +} + +QModelIndex AccessModel::index(int row, int column, + const QModelIndex &parent) const +{ + Q_D(const AccessModel); + if (row < d->rowCount()) { + return QIdentityProxyModel::index(row, column, parent); + } else { + return createIndex(row, column); + } +} + +#include "access-model.moc" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/access-model.h ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/access-model.h --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/access-model.h 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/access-model.h 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef OAU_ACCESS_MODEL_H +#define OAU_ACCESS_MODEL_H + +#include + +namespace OnlineAccountsUi { + +class AccessModelPrivate; +class AccessModel: public QIdentityProxyModel +{ + Q_OBJECT + Q_PROPERTY(QAbstractItemModel *accountModel READ accountModel \ + WRITE setAccountModel NOTIFY accountModelChanged) + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + Q_PROPERTY(QString lastItemText READ lastItemText WRITE setLastItemText \ + NOTIFY lastItemTextChanged) + Q_PROPERTY(QString applicationId READ applicationId \ + WRITE setApplicationId NOTIFY applicationIdChanged) + +public: + explicit AccessModel(QObject *parent = 0); + ~AccessModel(); + + void setAccountModel(QAbstractItemModel *accountModel); + QAbstractItemModel *accountModel() const; + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + + void setLastItemText(const QString &text); + QString lastItemText() const; + + void setApplicationId(const QString &applicationId); + QString applicationId() const; + + Q_INVOKABLE QVariant get(int row, const QString &roleName) const; + + QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + QHash roleNames() const Q_DECL_OVERRIDE; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +Q_SIGNALS: + void accountModelChanged(); + void countChanged(); + void lastItemTextChanged(); + void applicationIdChanged(); + +private: + AccessModelPrivate *d_ptr; + Q_DECLARE_PRIVATE(AccessModel) +}; + +} // namespace + +#endif // OAU_ACCESS_MODEL_H diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/account-manager.cpp ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/account-manager.cpp --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/account-manager.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/account-manager.cpp 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "account-manager.h" +#include "debug.h" + +using namespace OnlineAccountsUi; +using namespace Accounts; + +AccountManager *AccountManager::m_instance = 0; + +AccountManager *AccountManager::instance() +{ + if (!m_instance) { + m_instance = new AccountManager; + /* to ensure that all the installed services are parsed into + * libaccounts' DB, we enumerate them here. + * TODO: a click package hook would be a more proper fix. + */ + m_instance->serviceList(); + } + + return m_instance; +} + +AccountManager::AccountManager(QObject *parent): + Accounts::Manager(parent) +{ +} + +AccountManager::~AccountManager() +{ +} + +AccountIdList +AccountManager::accountListByProvider(const QString &providerId) const +{ + AccountIdList allAccounts = accountList(); + AccountIdList providerAccounts; + + Q_FOREACH(AccountId accountId, allAccounts) { + Account *account = this->account(accountId); + if (!account) continue; + + if (account->providerName() != providerId) continue; + + providerAccounts.append(accountId); + } + + return providerAccounts; +} diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/account-manager.h ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/account-manager.h --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/account-manager.h 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/account-manager.h 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef OAU_ACCOUNT_MANAGER_H +#define OAU_ACCOUNT_MANAGER_H + +#include + +namespace OnlineAccountsUi { + +class AccountManager: public Accounts::Manager +{ + Q_OBJECT + +public: + static AccountManager *instance(); + + Accounts::AccountIdList accountListByProvider( + const QString &providerId) const; + +protected: + explicit AccountManager(QObject *parent = 0); + ~AccountManager(); + +private: + static AccountManager *m_instance; +}; + +} // namespace + +#endif // OAU_ACCOUNT_MANAGER_H diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/application-manager.cpp ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/application-manager.cpp --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/application-manager.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/application-manager.cpp 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "account-manager.h" +#include "application-manager.h" +#include "debug.h" + +#include +#include +#include + +using namespace OnlineAccountsUi; + +ApplicationManager *ApplicationManager::m_instance = 0; + +namespace OnlineAccountsUi { +class ApplicationManagerPrivate +{ +public: + ApplicationManagerPrivate(); + + bool applicationMatchesProfile(const Accounts::Application &application, + const QString &profile) const; +}; +} // namespace + +ApplicationManagerPrivate::ApplicationManagerPrivate() +{ +} + +bool ApplicationManagerPrivate::applicationMatchesProfile(const Accounts::Application &application, + const QString &profile) const +{ + /* We don't restrict unconfined apps. */ + if (profile == QStringLiteral("unconfined")) return true; + + /* It's a confined app. We must make sure that the applicationId it + * specified matches the apparmor profile. + * + * For click packages, this is relatively easy: we load the .desktop + * file and checks whether the profile declared in the + * X-Ubuntu-Application-ID field is the same we are seeing. + * If we cannot determine that, then we assume that the application is not + * a click package, and we don't restrict it. */ + QString desktopFilePath = application.desktopFilePath(); + if (!QFile::exists(desktopFilePath)) { + DEBUG() << "Desktop file not found:" << desktopFilePath; + /* Every app, be it click or a package from the archive, should have a + * desktop file. If we don't find it, something is likely to be wrong + * and it's safer not to continue. */ + return false; + } + + QSettings desktopFile(desktopFilePath, QSettings::IniFormat); + QString appId = + desktopFile.value(QStringLiteral("Desktop Entry/X-Ubuntu-Application-ID")). + toString(); + if (appId.isEmpty()) { + // non click package? + return true; + } + + return appId == profile; +} + +ApplicationManager *ApplicationManager::instance() +{ + if (!m_instance) { + m_instance = new ApplicationManager; + } + + return m_instance; +} + +ApplicationManager::ApplicationManager(QObject *parent): + QObject(parent), + d_ptr(new ApplicationManagerPrivate) +{ +} + +ApplicationManager::~ApplicationManager() +{ + delete d_ptr; +} + +QVariantMap ApplicationManager::applicationInfo(const QString &claimedAppId, + const QString &profile) +{ + Q_D(const ApplicationManager); + + if (Q_UNLIKELY(profile.isEmpty())) return QVariantMap(); + + QString applicationId = claimedAppId; + if (profile.startsWith(applicationId)) { + /* Click packages might declare just the package name as application + * ID, but in order to find the correct application file we need the + * complete ID (with application title and version. */ + applicationId = profile; + } + + Accounts::Application application = + AccountManager::instance()->application(applicationId); + + /* Make sure that the app is who it claims to be */ + if (!d->applicationMatchesProfile(application, profile)) { + DEBUG() << "Given applicationId doesn't match profile"; + return QVariantMap(); + } + + QVariantMap app; + app.insert(QStringLiteral("id"), applicationId); + app.insert(QStringLiteral("displayName"), application.displayName()); + app.insert(QStringLiteral("icon"), application.iconName()); + app.insert(QStringLiteral("profile"), profile); + + /* List all the services supported by this application */ + QVariantList serviceIds; + Accounts::ServiceList allServices = + AccountManager::instance()->serviceList(); + Q_FOREACH(const Accounts::Service &service, allServices) { + if (!application.serviceUsage(service).isEmpty()) { + serviceIds.append(service.name()); + } + } + app.insert(QStringLiteral("services"), serviceIds); + + return app; +} + +QVariantMap ApplicationManager::providerInfo(const QString &providerId) const +{ + Accounts::Provider provider = + AccountManager::instance()->provider(providerId); + + QVariantMap info; + info.insert(QStringLiteral("id"), providerId); + info.insert(QStringLiteral("displayName"), provider.displayName()); + info.insert(QStringLiteral("icon"), provider.iconName()); + return info; +} diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/application-manager.h ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/application-manager.h --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/application-manager.h 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/application-manager.h 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef OAU_APPLICATION_MANAGER_H +#define OAU_APPLICATION_MANAGER_H + +#include +#include + +namespace OnlineAccountsUi { + +class ApplicationManagerPrivate; +class ApplicationManager: public QObject +{ + Q_OBJECT + +public: + static ApplicationManager *instance(); + + Q_INVOKABLE QVariantMap applicationInfo(const QString &applicationId, + const QString &profile); + QVariantMap providerInfo(const QString &providerId) const; + +protected: + explicit ApplicationManager(QObject *parent = 0); + ~ApplicationManager(); + +private: + static ApplicationManager *m_instance; + ApplicationManagerPrivate *d_ptr; + Q_DECLARE_PRIVATE(ApplicationManager) +}; + +} // namespace + +#endif // OAU_APPLICATION_MANAGER_H diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/com.ubuntu.OnlineAccountsUi.service.in ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/com.ubuntu.OnlineAccountsUi.service.in --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/com.ubuntu.OnlineAccountsUi.service.in 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/com.ubuntu.OnlineAccountsUi.service.in 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.ubuntu.OnlineAccountsUi +Exec=$${INSTALL_PREFIX}/bin/$${TARGET} --desktop_file_hint=$${desktop.path}/$${TARGET}.desktop diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/com.ubuntu.OnlineAccountsUi.xml ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/com.ubuntu.OnlineAccountsUi.xml --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/com.ubuntu.OnlineAccountsUi.xml 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/com.ubuntu.OnlineAccountsUi.xml 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,37 @@ + + + + + + + + + + + + diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/provider-request.cpp ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/provider-request.cpp --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/provider-request.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/provider-request.cpp 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "access-model.h" +#include "application-manager.h" +#include "debug.h" +#include "globals.h" +#include "provider-request.h" + +#include +#include +#include +#include +#include + +using namespace OnlineAccountsUi; + +static bool firstTime = true; + +namespace OnlineAccountsUi { + +class ProviderRequestPrivate: public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(ProviderRequest) + +public: + ProviderRequestPrivate(ProviderRequest *request); + ~ProviderRequestPrivate(); + + void start(); + +private Q_SLOTS: + void onWindowVisibleChanged(bool visible); + void onDenied(); + void onAllowed(int accountId); + +private: + QVariantMap providerInfo(const QString &providerId) const; + +private: + mutable ProviderRequest *q_ptr; + QQuickView *m_view; + QVariantMap m_applicationInfo; +}; + +} // namespace + +ProviderRequestPrivate::ProviderRequestPrivate(ProviderRequest *request): + QObject(request), + q_ptr(request), + m_view(0) +{ + if (firstTime) { + qmlRegisterType(); + qmlRegisterType("Ubuntu.OnlineAccounts.Internal", + 1, 0, "AccessModel"); + firstTime = false; + } +} + +ProviderRequestPrivate::~ProviderRequestPrivate() +{ + delete m_view; +} + +void ProviderRequestPrivate::start() +{ + Q_Q(ProviderRequest); + + QString applicationId = + q->parameters().value(OAU_KEY_APPLICATION).toString(); + ApplicationManager *appManager = ApplicationManager::instance(); + m_applicationInfo = + appManager->applicationInfo(applicationId, + q->clientApparmorProfile()); + if (Q_UNLIKELY(m_applicationInfo.isEmpty())) { + q->fail(OAU_ERROR_INVALID_APPLICATION, + QStringLiteral("Invalid client application")); + return; + } + + QString providerId = q->parameters().value(OAU_KEY_PROVIDER).toString(); + QVariantMap providerInfo = appManager->providerInfo(providerId); + + m_view = new QQuickView; + QObject::connect(m_view, SIGNAL(visibleChanged(bool)), + this, SLOT(onWindowVisibleChanged(bool))); + m_view->setResizeMode(QQuickView::SizeRootObjectToView); + m_view->engine()->addImportPath(PLUGIN_PRIVATE_MODULE_DIR); + + QQmlContext *context = m_view->rootContext(); + + context->setContextProperty("systemQmlPluginPath", + QUrl::fromLocalFile(OAU_PLUGIN_DIR)); + context->setContextProperty("localQmlPluginPath", + QUrl::fromLocalFile(QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation) + + "/accounts/qml-plugins/")); + context->setContextProperty("provider", providerInfo); + context->setContextProperty("application", m_applicationInfo); + context->setContextProperty("mainWindow", m_view); + + m_view->setSource(QUrl(QStringLiteral("qrc:/qml/ProviderRequest.qml"))); + QQuickItem *root = m_view->rootObject(); + QObject::connect(root, SIGNAL(denied()), + this, SLOT(onDenied())); + QObject::connect(root, SIGNAL(allowed(int)), + this, SLOT(onAllowed(int))); + q->setWindow(m_view); +} + +void ProviderRequestPrivate::onWindowVisibleChanged(bool visible) +{ + Q_Q(ProviderRequest); + + if (!visible) { + q->setResult(QVariantMap()); + } +} + +void ProviderRequestPrivate::onDenied() +{ + DEBUG(); + /* Just close the window; this will deliver the empty result to the + * client */ + m_view->close(); +} + +void ProviderRequestPrivate::onAllowed(int accountId) +{ + Q_Q(ProviderRequest); + DEBUG() << "Access allowed for account:" << accountId; + QVariantMap result; + result.insert("accountId", quint32(accountId)); + q->setResult(result); + m_view->close(); +} + +ProviderRequest::ProviderRequest(const QDBusConnection &connection, + const QDBusMessage &message, + const QVariantMap ¶meters, + QObject *parent): + Request(connection, message, parameters, parent), + d_ptr(new ProviderRequestPrivate(this)) +{ +} + +ProviderRequest::~ProviderRequest() +{ +} + +void ProviderRequest::start() +{ + Q_D(ProviderRequest); + Request::start(); + d->start(); +} + +#include "provider-request.moc" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/provider-request.h ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/provider-request.h --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/provider-request.h 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/provider-request.h 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef OAU_PROVIDER_REQUEST_H +#define OAU_PROVIDER_REQUEST_H + +#include "request.h" + +namespace OnlineAccountsUi { + +class ProviderRequestPrivate; +class ProviderRequest: public Request +{ + Q_OBJECT + +public: + explicit ProviderRequest(const QDBusConnection &connection, + const QDBusMessage &message, + const QVariantMap ¶meters, + QObject *parent = 0); + ~ProviderRequest(); + + void start() Q_DECL_OVERRIDE; + +private: + ProviderRequestPrivate *d_ptr; + Q_DECLARE_PRIVATE(ProviderRequest) +}; + +} // namespace + +#endif // OAU_PROVIDER_REQUEST_H diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/qml/AuthorizationPage.qml ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/qml/AuthorizationPage.qml --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/qml/AuthorizationPage.qml 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/qml/AuthorizationPage.qml 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +import QtQuick 2.0 +import Ubuntu.Components 0.1 +import Ubuntu.Components.ListItems 0.1 as ListItem + +Flickable { + id: root + + property variant model + property variant application + property variant provider + + signal allowed(int accountId) + signal denied + signal createAccount + + Column { + anchors.left: parent.left + anchors.right: parent.right + + Label { + anchors.left: parent.left + anchors.right: parent.right + text: i18n.tr("%1 wants to access your %2 account"). + arg(application.displayName).arg(provider.displayName); + wrapMode: Text.WordWrap + } + + ListItem.ItemSelector { + id: accountSelector + anchors.left: parent.left + anchors.right: parent.right + text: "Account" + model: root.model + delegate: OptionSelectorDelegate { + property string modelData: model.displayName + } + onDelegateClicked: { + /* The last item in the model is the "Add another..." label */ + if (index == model.count - 1) root.createAccount(); + } + } + + Button { + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width - units.gu(4) + text: i18n.tr("Allow") + onClicked: root.allowed(root.model.get(accountSelector.selectedIndex, "accountId")) + } + + Button { + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width - units.gu(4) + text: i18n.tr("Don't allow") + onClicked: root.denied() + } + } +} diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/qml/ProviderRequest.qml ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/qml/ProviderRequest.qml --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/src/qml/ProviderRequest.qml 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/src/qml/ProviderRequest.qml 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +import QtQuick 2.0 +import Ubuntu.Components 0.1 +import Ubuntu.OnlineAccounts 0.1 +import Ubuntu.OnlineAccounts.Internal 1.0 + +MainView { + id: root + + property variant applicationInfo: application + property variant providerInfo: provider + property int __createdAccountId: 0 + + signal denied + signal allowed(int accountId) + + width: units.gu(48) + height: units.gu(60) + + Component.onCompleted: { + i18n.domain = "ubuntu-system-settings-online-accounts" + loader.active = true + pageStack.push(mainPage) + } + + on__CreatedAccountIdChanged: grantAccessIfReady() + + PageStack { + id: pageStack + + Page { + id: mainPage + title: i18n.tr("Online Accounts") + + Loader { + id: loader + anchors.fill: parent + active: false + sourceComponent: accessModel.count <= 1 ? accountCreationPage : authorizationPage + onLoaded: { + // use this trick to break the sourceComponent binding + var tmp = sourceComponent + sourceComponent = tmp + } + } + } + } + + AccountServiceModel { + id: accountsModel + service: "global" + provider: providerInfo.id + includeDisabled: true + onCountChanged: root.grantAccessIfReady() + + function indexOfAccount(accountId) { + for (var i = 0; i < accountsModel.count; i++) { + if (accountsModel.get(i, "accountId") == accountId) + return i + } + return -1 + } + } + + AccessModel { + id: accessModel + accountModel: accountsModel + applicationId: applicationInfo.id + lastItemText: i18n.tr("Add another") + } + + Component { + id: accountCreationPage + AccountCreationPage { + providerId: providerInfo.id + onFinished: { + if (accountId == 0) root.denied() + /* if an account was created, just remember its ID. when the + * accountsModel will notice it we'll proceed with the access + * grant */ + else root.__createdAccountId = accountId + } + } + } + + Component { + id: authorizationPage + AuthorizationPage { + model: accessModel + application: applicationInfo + provider: providerInfo + onDenied: root.denied() + onAllowed: root.grantAccess(accountId) + onCreateAccount: pageStack.push(accountCreationPage) + } + } + + Component { + id: createAccountPageComponent + Page { + title: i18n.tr("Online Accounts") + Loader { + anchors.fill: parent + sourceComponent: accountCreationPage + } + } + } + + Component { + id: accountServiceComponent + AccountService { + autoSync: false + } + } + + Account { + id: account + onSynced: accountEnablingDone() + } + + AccountService { + id: globalAccountService + objectHandle: account.accountServiceHandle + credentials: accountCredentials + autoSync: false + } + + AccountServiceModel { + id: accountServiceModel + includeDisabled: true + account: account.objectHandle + } + + Credentials { + id: accountCredentials + credentialsId: globalAccountService.objectHandle != null ? globalAccountService.authData.credentialsId : 0 + onSynced: { + console.log("Credentials ready (store secret = " + storeSecret + ")") + if (acl.indexOf(applicationInfo.profile) >= 0) { + console.log("Application is in ACL: " + acl) + root.aclDone() + return + } + acl.push(applicationInfo.profile) + sync() + } + } + + function grantAccessIfReady() { + if (root.__createdAccountId != 0 && + accountsModel.indexOfAccount(root.__createdAccountId) >= 0) { + root.grantAccess(root.__createdAccountId) + root.__createdAccountId = 0 + } + } + + function grantAccess(accountId) { + console.log("granting access to account " + accountId) + // find the index in the model for this account + var i = accountsModel.indexOfAccount(accountId) + if (i < 0) { + // very unlikely; maybe the account has been deleted in the meantime + console.log("Account not found:" + accountId) + root.denied() + return + } + + // setting this will trigger the update of the ACL + account.objectHandle = accountsModel.get(i, "accountHandle") + } + + function aclDone() { + console.log("acl done") + /* now we can enable the application services in the account. */ + for (var i = 0; i < accountServiceModel.count; i++) { + var accountService = accountServiceComponent.createObject(null, { + "objectHandle": accountServiceModel.get(i, "accountServiceHandle") + }) + console.log("Account service account id: " + accountService.accountId) + var serviceId = accountService.service.id + if (applicationInfo.services.indexOf(serviceId) >= 0 && + !accountService.serviceEnabled) { + console.log("Enabling service " + serviceId) + accountService.updateServiceEnabled(true) + } + /* The accountService is just a convenience object: all the changes + * are stored in the account object. So we can destroy this one. */ + accountService.destroy() + } + + // Store the changes + account.sync() + } + + function accountEnablingDone() { + console.log("account enabling done") + allowed(account.accountId) + } +} diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/client/tst_client.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/client/tst_client.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/client/tst_client.pro 2013-12-05 08:41:46.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/client/tst_client.pro 2014-03-07 08:36:51.000000000 +0000 @@ -21,6 +21,6 @@ QMAKE_RPATHDIR = $${QMAKE_LIBDIR} LIBS += -lonline-accounts-client -check.commands = "xvfb-run -a dbus-test-runner -t ./$${TARGET}" +check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}" check.depends = $${TARGET} QMAKE_EXTRA_TARGETS += check diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/client/tst_qml_client.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/client/tst_qml_client.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/client/tst_qml_client.pro 2013-12-05 08:41:46.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/client/tst_qml_client.pro 2014-03-07 08:36:51.000000000 +0000 @@ -20,6 +20,6 @@ DEFINES += \ PLUGIN_PATH=\\\"$${PLUGIN_PATH}\\\" -check.commands = "LD_LIBRARY_PATH=$${TOP_BUILD_DIR}/client/OnlineAccountsClient:${LD_LIBRARY_PATH} xvfb-run -a dbus-test-runner -t ./$${TARGET}" +check.commands = "LD_LIBRARY_PATH=$${TOP_BUILD_DIR}/client/OnlineAccountsClient:${LD_LIBRARY_PATH} xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}" check.depends = $${TARGET} QMAKE_EXTRA_TARGETS += check diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/applications/mailer.desktop ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/applications/mailer.desktop --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/applications/mailer.desktop 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/applications/mailer.desktop 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Easy Mailer +Comment=Send and receive mail +Exec=/bin/sh +Icon=mailer-icon +Terminal=false +Type=Application +Categories=Application;Network;Email; diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/coolmail.service ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/coolmail.service --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/coolmail.service 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/coolmail.service 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,19 @@ + + + e-mail + Cool Mail + general_myservice + cool + + + diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/cool.provider ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/cool.provider --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/cool.provider 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/cool.provider 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,6 @@ + + + Cool provider + general_myprovider + true + diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/coolshare.service ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/coolshare.service --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/coolshare.service 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/coolshare.service 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,7 @@ + + + sharing + Cool Share + general_otherservice + cool + diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/mailer.application ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/mailer.application --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/data/mailer.application 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/data/mailer.application 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,18 @@ + + + Mailer application + mailer-catalog + mailer.desktop + + + + Mailer can retrieve your e-mails + + + + + + Mailer can even share stuff on CoolShare + + + diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/qml/qml.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/qml/qml.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/qml/qml.pro 2013-12-05 08:41:46.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/qml/qml.pro 2014-03-07 08:36:51.000000000 +0000 @@ -9,6 +9,6 @@ SOURCES += \ tst_online_accounts_qml.cpp -check.commands = "xvfb-run -a dbus-test-runner -t " +check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t " check.depends = $${TARGET} QMAKE_EXTRA_TARGETS += check diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_access_model.cpp ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_access_model.cpp --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_access_model.cpp 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_access_model.cpp 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2013 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This file is part of online-accounts-ui + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "access-model.h" +#include "debug.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace OnlineAccountsUi; + +class AccessModelTest: public QObject +{ + Q_OBJECT + +public: + AccessModelTest(); + +private Q_SLOTS: + void initTestCase(); + void testEmpty(); + void testProxy(); + void testEnabling(); + +private: + void clearDb(); +}; + +AccessModelTest::AccessModelTest(): + QObject(0) +{ + setLoggingLevel(2); +} + +void AccessModelTest::clearDb() +{ + QDir dbroot(QString::fromLatin1(qgetenv("ACCOUNTS"))); + dbroot.remove("accounts.db"); +} + +void AccessModelTest::initTestCase() +{ + qputenv("ACCOUNTS", "/tmp/"); + qputenv("AG_APPLICATIONS", TEST_DATA_DIR); + qputenv("AG_SERVICES", TEST_DATA_DIR); + qputenv("AG_SERVICE_TYPES", TEST_DATA_DIR); + qputenv("AG_PROVIDERS", TEST_DATA_DIR); + qputenv("XDG_DATA_HOME", TEST_DATA_DIR); + + clearDb(); +} + +void AccessModelTest::testEmpty() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import Ubuntu.OnlineAccounts 0.1\n" + "AccountServiceModel {\n" + " provider: \"cool\"\n" + " service: \"global\"\n" + "}", + QUrl()); + QAbstractListModel *accountModel = + qobject_cast(component.create()); + QVERIFY(accountModel != 0); + + QCOMPARE(accountModel->property("count").toInt(), 0); + + /* Create the access model */ + AccessModel *model = new AccessModel(this); + QVERIFY(model != 0); + + QCOMPARE(model->lastItemText(), QString()); + QCOMPARE(model->applicationId(), QString()); + QVERIFY(model->accountModel() == 0); + + model->setLastItemText("hello"); + QCOMPARE(model->lastItemText(), QString("hello")); + + QCOMPARE(model->rowCount(), 1); + QCOMPARE(model->get(0, "displayName").toString(), QString("hello")); + + model->setAccountModel(accountModel); + QCOMPARE(model->rowCount(), 1); + + delete model; + delete accountModel; +} + +void AccessModelTest::testProxy() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import Ubuntu.OnlineAccounts 0.1\n" + "AccountServiceModel {\n" + " provider: \"cool\"\n" + " service: \"global\"\n" + "}", + QUrl()); + QAbstractListModel *accountModel = + qobject_cast(component.create()); + QVERIFY(accountModel != 0); + + QCOMPARE(accountModel->property("count").toInt(), 0); + + /* Create the access model */ + AccessModel *model = new AccessModel(this); + QVERIFY(model != 0); + + model->setLastItemText("hello"); + model->setAccountModel(accountModel); + model->setApplicationId("mailer"); + QCOMPARE(model->rowCount(), 1); + + /* Now add and remove accounts, and see that the accessModel picks them up */ + QSignalSpy rowsInserted(model, + SIGNAL(rowsInserted(const QModelIndex&,int,int))); + QSignalSpy rowsRemoved(model, + SIGNAL(rowsRemoved(const QModelIndex&,int,int))); + + Accounts::Manager *manager = new Accounts::Manager(this); + Accounts::Account *account1 = manager->createAccount("cool"); + QVERIFY(account1 != 0); + account1->setEnabled(true); + account1->setDisplayName("CoolAccount"); + account1->syncAndBlock(); + + rowsInserted.wait(); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(rowsInserted.count(), 1); + QCOMPARE(rowsRemoved.count(), 0); + rowsInserted.clear(); + QCOMPARE(model->get(0, "displayName").toString(), QString("CoolAccount")); + + /* Create a second account */ + Accounts::Account *account2 = manager->createAccount("cool"); + QVERIFY(account2 != 0); + account2->setEnabled(true); + account2->setDisplayName("UncoolAccount"); + account2->syncAndBlock(); + + rowsInserted.wait(); + QCOMPARE(model->rowCount(), 3); + QCOMPARE(rowsInserted.count(), 1); + int row = rowsInserted.at(0).at(1).toInt(); + QCOMPARE(rowsRemoved.count(), 0); + rowsInserted.clear(); + QCOMPARE(model->get(row, "displayName").toString(), QString("UncoolAccount")); + + /* Delete the first account */ + account1->remove(); + account1->syncAndBlock(); + rowsRemoved.wait(); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(rowsInserted.count(), 0); + QCOMPARE(rowsRemoved.count(), 1); + rowsRemoved.clear(); + QCOMPARE(model->get(0, "displayName").toString(), QString("UncoolAccount")); + + /* Delete also the second account */ + account2->remove(); + account2->syncAndBlock(); + rowsRemoved.wait(); + QCOMPARE(model->rowCount(), 1); + QCOMPARE(rowsInserted.count(), 0); + QCOMPARE(rowsRemoved.count(), 1); + rowsRemoved.clear(); + QCOMPARE(model->get(0, "displayName").toString(), QString("hello")); + + delete model; + delete accountModel; +} + +void AccessModelTest::testEnabling() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import Ubuntu.OnlineAccounts 0.1\n" + "AccountServiceModel {\n" + " provider: \"cool\"\n" + " service: \"global\"\n" + "}", + QUrl()); + QAbstractListModel *accountModel = + qobject_cast(component.create()); + QVERIFY(accountModel != 0); + + QCOMPARE(accountModel->property("count").toInt(), 0); + + /* Create the access model */ + AccessModel *model = new AccessModel(this); + QVERIFY(model != 0); + + model->setLastItemText("hello"); + model->setAccountModel(accountModel); + model->setApplicationId("mailer"); + QCOMPARE(model->rowCount(), 1); + + /* Now add two accounts, but verify that the model should expose only the + * one which has at least one service disabled */ + QSignalSpy rowsInserted(model, + SIGNAL(rowsInserted(const QModelIndex&,int,int))); + QSignalSpy rowsRemoved(model, + SIGNAL(rowsRemoved(const QModelIndex&,int,int))); + + Accounts::Manager *manager = new Accounts::Manager(this); + Accounts::Service coolMail = manager->service("coolmail"); + Accounts::Service coolShare = manager->service("coolshare"); + Accounts::Account *account1 = manager->createAccount("cool"); + QVERIFY(account1 != 0); + account1->setEnabled(true); + account1->setDisplayName("CoolAccount"); + account1->selectService(coolMail); + account1->setEnabled(true); + account1->syncAndBlock(); + + rowsInserted.wait(); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(rowsInserted.count(), 1); + QCOMPARE(rowsRemoved.count(), 0); + rowsInserted.clear(); + QCOMPARE(model->get(0, "displayName").toString(), QString("CoolAccount")); + + /* Create a second account, enable all of its services */ + Accounts::Account *account2 = manager->createAccount("cool"); + QVERIFY(account2 != 0); + account2->setEnabled(true); + account2->setDisplayName("UncoolAccount"); + account2->selectService(coolMail); + account2->setEnabled(true); + account2->selectService(coolShare); + account2->setEnabled(true); + account2->syncAndBlock(); + + /* Verify that a row is *not* added */ + QTest::qWait(50); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(rowsInserted.count(), 0); + QCOMPARE(rowsRemoved.count(), 0); + rowsInserted.clear(); + + delete model; + delete accountModel; +} + +QTEST_MAIN(AccessModelTest); + +#include "tst_access_model.moc" diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_access_model.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_access_model.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_access_model.pro 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_access_model.pro 2014-03-07 08:36:51.000000000 +0000 @@ -0,0 +1,38 @@ +include(../../common-project-config.pri) + +TARGET = tst_access_model + +CONFIG += \ + debug \ + link_pkgconfig + +QT += \ + core \ + dbus \ + qml \ + testlib + +PKGCONFIG += \ + accounts-qt5 + +DEFINES += \ + DEBUG_ENABLED \ + TEST_DATA_DIR=\\\"$${PWD}/data\\\" + +SOURCES += \ + $${TOP_SRC_DIR}/src/access-model.cpp \ + $${TOP_SRC_DIR}/src/account-manager.cpp \ + $${TOP_SRC_DIR}/src/debug.cpp \ + tst_access_model.cpp + +HEADERS += \ + $${TOP_SRC_DIR}/src/access-model.h \ + $${TOP_SRC_DIR}/src/account-manager.h \ + $${TOP_SRC_DIR}/src/debug.h + +INCLUDEPATH += \ + $${TOP_SRC_DIR}/src + +check.commands = "xvfb-run -a dbus-test-runner -t ./$${TARGET}" +check.depends = $${TARGET} +QMAKE_EXTRA_TARGETS += check diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_inactivity_timer.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_inactivity_timer.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_inactivity_timer.pro 2013-12-05 08:41:46.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_inactivity_timer.pro 2014-03-07 08:36:51.000000000 +0000 @@ -19,6 +19,6 @@ INCLUDEPATH += \ $${TOP_SRC_DIR}/src -check.commands = "xvfb-run -a ./$${TARGET}" +check.commands = "xvfb-run -s '-screen 0 640x480x24' -a ./$${TARGET}" check.depends = $${TARGET} QMAKE_EXTRA_TARGETS += check diff -Nru ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_service.pro ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_service.pro --- ubuntu-system-settings-online-accounts-0.3+14.04.20140304.is.0.2~+14.04.20131205/tests/online-accounts-ui/tst_service.pro 2013-12-05 08:41:46.000000000 +0000 +++ ubuntu-system-settings-online-accounts-0.3+14.04.20140307.1/tests/online-accounts-ui/tst_service.pro 2014-03-07 08:36:51.000000000 +0000 @@ -29,6 +29,6 @@ INCLUDEPATH += \ $${TOP_SRC_DIR}/src -check.commands = "xvfb-run -a dbus-test-runner -t ./$${TARGET}" +check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}" check.depends = $${TARGET} QMAKE_EXTRA_TARGETS += check