fixed: 212882 - Account setup finished view label font size is not proper
[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-priv.h"
46 #include "accountsmanagersingleton.h"
47 #include "last-page-actions.h"
48 #include "provider-plugin-process.h"
49 #include "account-setup-finished-widget.h"
50
51 namespace AccountsUI {
52
53 void AccountSetupFinishedPagePrivate::actionButtonClicked()
54 {
55     QString serviceName = sender()->property("serviceName").toString();
56     qDebug() << "Invoking service" << serviceName;
57     LastPageActions::executeService(serviceName);
58     ProviderPluginProcess::instance()->quit();
59 }
60
61 AccountSetupFinishedPage::AccountSetupFinishedPage(AbstractAccountSetupContext *context)
62         : MApplicationPage(),
63           d_ptr(new AccountSetupFinishedPagePrivate())
64 {
65     Q_D(AccountSetupFinishedPage);
66     d->q_ptr = this;
67     d->account = context->account();
68     d->serviceType = context->serviceType();
69     setObjectName("AccountSetupFinishedPage");
70 }
71
72 AccountSetupFinishedPage::~AccountSetupFinishedPage()
73 {
74     delete d_ptr;
75 }
76
77 void AccountSetupFinishedPage::createContent()
78 {
79     Q_D(AccountSetupFinishedPage);
80
81     setComponentsDisplayMode(EscapeButton, MApplicationPageModel::Hide);
82
83     MWidget *centralWidget = new MWidget();
84     MLayout *layout = new MLayout(centralWidget);
85     MLinearLayoutPolicy *layoutPolicy = new MLinearLayoutPolicy(layout, Qt::Vertical);
86     layoutPolicy->setSpacing(0);
87
88     QString providerName(d->account->providerName());
89     // xml file that describes the ui elements for the provider
90     Accounts::Provider *provider = AccountsManager::instance()->provider(providerName);
91     if (provider) {
92         QDomElement root = provider->domDocument().documentElement();
93         QDomElement providerIcon = root.firstChildElement("icon");
94         QString providerIconId = providerIcon.text();
95
96         MContentItem *providerItem = new MContentItem(MContentItem::IconAndSingleTextLabel, this);
97         providerItem->setStyleName("SetupFinishedProviderName");
98         providerItem->setImageID(providerIconId);
99         providerItem->setTitle(provider->displayName());
100         layoutPolicy->addItem(providerItem);
101     }
102
103     MSeparator *separatorTop = new MSeparator(this);
104     separatorTop->setOrientation(Qt::Horizontal);
105
106     layoutPolicy->addItem(separatorTop);
107
108     AccountSetupFinishedWidget *widget = new AccountSetupFinishedWidget(providerName, this);
109     layoutPolicy->addItem(widget);
110
111     //% "Add more account"
112     MButton *addMoreAccountButton = new MButton(qtTrId("qtn_acc_add_more_accounts"));
113     connect (addMoreAccountButton, SIGNAL(clicked()), ProviderPluginProcess::instance(), SLOT(quit()));
114     MLayout *buttonsLayout = new MLayout();
115     MLinearLayoutPolicy *portraitPolicy = new MLinearLayoutPolicy(buttonsLayout, Qt::Vertical);
116     MLinearLayoutPolicy *landscapePolicy = new MLinearLayoutPolicy(buttonsLayout, Qt::Horizontal);
117
118     portraitPolicy->addStretch();
119     portraitPolicy->setSpacing(20);
120     landscapePolicy->addStretch();
121     landscapePolicy->setSpacing(20);
122
123     const LastPageActions &lastPageActions =
124         ProviderPluginProcess::instance()->lastPageActions();
125     const LastPageActions::ServiceActionList actions =
126         lastPageActions.serviceActions();
127     foreach (LastPageActions::ServiceAction action, actions) {
128         MButton *button = new MButton(qtTrId("qtn_comm_go_to_x").
129                                       arg(action.title()));
130         button->setProperty("serviceName", action.serviceName());
131         connect(button, SIGNAL(clicked()), d, SLOT(actionButtonClicked()));
132
133         landscapePolicy->addItem(button, Qt::AlignRight);
134         portraitPolicy->addItem(button, Qt::AlignCenter);
135     }
136
137     portraitPolicy->addItem(addMoreAccountButton, Qt::AlignCenter);
138     landscapePolicy->addItem(addMoreAccountButton, Qt::AlignCenter);
139
140     portraitPolicy->addStretch();
141     landscapePolicy->addStretch();
142
143     buttonsLayout->setLandscapePolicy(landscapePolicy);
144     buttonsLayout->setPortraitPolicy(portraitPolicy);
145     layoutPolicy->addStretch();
146     layoutPolicy->addItem(buttonsLayout);
147
148     setCentralWidget(centralWidget);
149
150 }
151
152 void AccountSetupFinishedPage::goToApplication()
153 {
154     /* this slot is deprecated */
155 }
156
157 }