Fixing: 249040 - Switch labels should not highlight text on press
[accounts-sso:libaccounts-ui.git] / lib / AccountsUI / settings-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 //project
24 #include "settings-page.h"
25 #include "abstract-service-setup-context.h"
26 #include "accountsmanagersingleton.h"
27 #include "service-helper.h"
28
29 //Accounts
30 #include <Accounts/Account>
31 #include <Accounts/Provider>
32
33 //M
34 #include <MWidget>
35 #include <MLayout>
36 #include <MLinearLayoutPolicy>
37 #include <MGridLayoutPolicy>
38 #include <MLabel>
39 #include <MButton>
40 #include <MDetailedListItem>
41 #include <MSeparator>
42 #include <MImageWidget>
43 #include <MPannableViewport>
44 #include <MPositionIndicator>
45
46 //Qt
47 #include <QDebug>
48
49 namespace AccountsUI {
50
51 class SettingsPagePrivate
52 {
53 public:
54     SettingsPagePrivate()
55             : context(0)
56             , enableButton(0),
57             buttonModel(0)
58     {}
59     ~SettingsPagePrivate(){}
60     AbstractServiceSetupContext *context;
61     MButton *enableButton;
62     MButtonModel *buttonModel;
63 };
64
65 SettingsPage::SettingsPage(AbstractServiceSetupContext *context,
66                            MButtonModel *model,
67                            QGraphicsItem *parent)
68     : MApplicationPage(parent)
69     , d_ptr(new SettingsPagePrivate())
70 {
71     Q_D(SettingsPage);
72     d->context = context;
73     d->buttonModel = model;
74     connect(this, SIGNAL(backButtonClicked()), d->context, SLOT(store()));
75     pannableViewport()->positionIndicator()->setStyleName("CommonPositionIndicatorInverted");
76 }
77
78 SettingsPage::~SettingsPage()
79 {
80     delete d_ptr;
81 }
82
83 void SettingsPage::createContent()
84 {
85     Q_D(SettingsPage);
86
87     setStyleName("AccountsUiPage");
88
89     //% "%1 settings"
90     setTitle(qtTrId("qtn_acc_ser_prof_set_title").arg(d->context->service()->name()));
91
92     MWidget *upperWidget = new MWidget(this);
93     MLayout *upperLayout = new MLayout(upperWidget);
94     MLinearLayoutPolicy *upperLayoutPolicy = new MLinearLayoutPolicy(upperLayout, Qt::Vertical);
95     upperLayoutPolicy->setSpacing(0);
96
97     MLayout *horizontalLayout = new MLayout();
98     MLinearLayoutPolicy *horizontalLayoutPolicy = new MLinearLayoutPolicy(horizontalLayout, Qt::Horizontal);
99
100     QString providerName(d->context->account()->providerName());
101     QString providerIconId;
102     // xml file that describes the ui elements for the provider
103     Accounts::Provider *provider = AccountsManager::instance()->provider(providerName);
104     if (provider) {
105         QDomElement root = provider->domDocument().documentElement();
106         QDomElement providerIcon = root.firstChildElement("icon");
107         providerIconId = providerIcon.text();
108     }
109
110     ServiceHelper *serviceHepler =
111         new ServiceHelper(const_cast<Accounts::Service*>(d->context->service()), this);
112     BasicHeaderWidget *usernameAndStatus = 0;
113
114     if (d->context->account()->id() == 0) {
115         usernameAndStatus = new BasicHeaderWidget(BasicHeaderWidget::IconWithTitle, this);
116         usernameAndStatus->createLayout();
117     } else {
118         usernameAndStatus = new BasicHeaderWidget(BasicHeaderWidget::IconWithTitleAndSubTitle, this);
119         usernameAndStatus->createLayout();
120         usernameAndStatus->setSubtitle(qtTrId(d->context->account()->displayName().toLatin1()));
121     }
122
123     usernameAndStatus->setImage(providerIconId);
124     usernameAndStatus->setTitle(serviceHepler->prettyName());
125     usernameAndStatus->setSubtitle(serviceHepler->description());
126
127     MSeparator *separatorTop = new MSeparator(this);
128     separatorTop->setStyleName("CommonHeaderDividerInverted");
129     separatorTop->setOrientation(Qt::Horizontal);
130
131     d->context->account()->selectService(d->context->service());
132
133     horizontalLayoutPolicy->addItem(usernameAndStatus, Qt::AlignLeft | Qt::AlignVCenter);
134     upperLayoutPolicy->addItem(horizontalLayout);
135     upperLayoutPolicy->addItem(separatorTop);
136
137     MWidget *widget = d->context->widget(this);
138
139     MWidget *centralWidget = new MWidget(this);
140     MLayout *layout = new MLayout(centralWidget);
141     MLinearLayoutPolicy *layoutPolicy = new MLinearLayoutPolicy(layout, Qt::Vertical);
142     layoutPolicy->addItem(upperWidget);
143
144     layoutPolicy->addItem(widget);
145     layoutPolicy->addStretch();
146
147     setCentralWidget(centralWidget);
148 }
149
150 }//end of namespace
151