Success page added
[accounts-sso:libaccounts-ui.git] / lib / AccountsUI / account-setup-finished-page.cpp
1 /*
2  * This file is part of accounts-ui
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22
23 //libAccounts
24 #include <Accounts/Provider>
25 #include <Accounts/Account>
26 #include <Accounts/ServiceType>
27 #include <Accounts/Manager>
28
29 //Meegotouch
30 #include <MLayout>
31 #include <MLinearLayoutPolicy>
32 #include <MContentItem>
33 #include <MLocale>
34 #include <MAction>
35 #include <MLabel>
36 #include <MGridLayoutPolicy>
37 #include <MSeparator>
38 #include <MImageWidget>
39 #include <MButton>
40
41 //Qt
42 #include <QDebug>
43
44 //Accounts-Ui
45 #include "account-setup-finished-page.h"
46 #include "accountsmanagersingleton.h"
47 #include "provider-plugin-process.h"
48
49 namespace AccountsUI {
50
51
52 class AccountSetupFinishedPagePrivate
53 {
54 public:
55     AccountSetupFinishedPagePrivate()
56             : account(0)
57     {}
58
59     ~AccountSetupFinishedPagePrivate() {}
60     Accounts::Account *account;
61     QString serviceType;
62 };
63
64 AccountSetupFinishedPage::AccountSetupFinishedPage(AbstractAccountSetupContext *context)
65         : MApplicationPage(),
66           d_ptr(new AccountSetupFinishedPagePrivate())
67 {
68     Q_D(AccountSetupFinishedPage);
69     d->account = context->account();
70     d->serviceType = context->serviceType();
71     setObjectName("AccountSetupFinishedPage");
72 }
73
74 AccountSetupFinishedPage::~AccountSetupFinishedPage()
75 {
76     delete d_ptr;
77 }
78
79 void AccountSetupFinishedPage::createContent()
80 {
81     Q_D(AccountSetupFinishedPage);
82     MWidget *centralWidget = new MWidget();
83     MLayout *layout = new MLayout(centralWidget);
84     MLinearLayoutPolicy *layoutPolicy = new MLinearLayoutPolicy(layout, Qt::Vertical);
85     layoutPolicy->setSpacing(0);
86
87     QString providerName(d->account->providerName());
88     // xml file that describes the ui elements for the provider
89     Accounts::Provider *provider = AccountsManager::instance()->provider(providerName);
90     if (provider) {
91         QDomElement root = provider->domDocument().documentElement();
92         QDomElement providerIcon = root.firstChildElement("icon");
93         QString providerIconId = providerIcon.text();
94
95         MContentItem *providerItem = new MContentItem(MContentItem::IconAndSingleTextLabel, this);
96         providerItem->setStyleName("SetupFinishedProviderName");
97         providerItem->setImageID(providerIconId);
98         providerItem->setTitle(provider->displayName());
99         layoutPolicy->addItem(providerItem);
100     }
101
102     MSeparator *separatorTop = new MSeparator(this);
103     separatorTop->setOrientation(Qt::Horizontal);
104
105     layoutPolicy->addItem(separatorTop);
106
107     // %"Success"
108     MLabel *successLabel = new MLabel(qtTrId("qtn_acc_success"));
109     successLabel->setStyleName("SuccessLabel");
110     successLabel->setAlignment(Qt::AlignCenter);
111
112     // %"Your %1 account is connected!"
113     MLabel *firstDescLabel = new MLabel(qtTrId("qtn_acc_account_connected").arg(providerName));
114     firstDescLabel->setStyleName("FirstDescLabel");
115     firstDescLabel->setAlignment(Qt::AlignCenter);
116
117     // %"Fetching your data"
118     MLabel *secondDescLabel = new MLabel(qtTrId("qtn_acc_fetching_your_data"));
119     secondDescLabel->setStyleName("SecondDescLabel");
120     secondDescLabel->setAlignment(Qt::AlignCenter);
121
122     layoutPolicy->addItem(successLabel, Qt::AlignCenter);
123     layoutPolicy->addItem(firstDescLabel, Qt::AlignCenter);
124     layoutPolicy->addItem(secondDescLabel, Qt::AlignCenter);
125
126     Accounts::ServiceType *type = AccountsManager::instance()->serviceType(d->serviceType);
127
128     //% "Go to %1"
129     MButton *goToButton = new MButton(qtTrId("qtn_comm_go_to_x").arg(type->displayName()));
130
131     connect (goToButton, SIGNAL(clicked()), this, SLOT(goToApplication()));
132     //% "Add more account"
133     MButton *addMoreAccountButton = new MButton(qtTrId("qtn_acc_add_more_accounts"));
134     connect (addMoreAccountButton, SIGNAL(clicked()), ProviderPluginProcess::instance(), SLOT(quit()));
135     MLayout *buttonsLayout = new MLayout();
136     MLinearLayoutPolicy *portraitPolicy = new MLinearLayoutPolicy(buttonsLayout, Qt::Vertical);
137     MLinearLayoutPolicy *landscapePolicy = new MLinearLayoutPolicy(buttonsLayout, Qt::Horizontal);
138
139     portraitPolicy->addStretch();
140     portraitPolicy->setSpacing(20);
141     landscapePolicy->setSpacing(20);
142
143     portraitPolicy->addItem(goToButton, Qt::AlignCenter);
144     portraitPolicy->addStretch();
145     portraitPolicy->addItem(addMoreAccountButton, Qt::AlignCenter);
146     landscapePolicy->addStretch();
147     landscapePolicy->addItem(goToButton, Qt::AlignRight);
148
149     landscapePolicy->addItem(addMoreAccountButton, Qt::AlignCenter);
150     landscapePolicy->addStretch();
151
152     buttonsLayout->setLandscapePolicy(landscapePolicy);
153     buttonsLayout->setPortraitPolicy(portraitPolicy);
154     layoutPolicy->addStretch();
155     layoutPolicy->addItem(buttonsLayout);
156
157     setCentralWidget(centralWidget);
158
159 }
160
161 void AccountSetupFinishedPage::goToApplication()
162 {
163     ProviderPluginProcess::instance()->setReturnToApp(true);
164     ProviderPluginProcess::instance()->quit();
165 }
166
167 }