63
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0""
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Certificate trust settings view in advanced security settings
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "advsecsettingscerttrustsettingsview.h"
|
|
19 |
#include "advsecsettingstrustedcertusageuids.h"
|
|
20 |
#include "advsecsettingscertificatemodel.h"
|
|
21 |
#include "advsecsettingscertificate.h"
|
|
22 |
#include <QGraphicsLinearLayout>
|
|
23 |
#include <HbGroupBox>
|
|
24 |
#include <HbDataForm>
|
|
25 |
#include <HbDataFormModel>
|
|
26 |
#include <HbMenu>
|
|
27 |
#include <HbAction>
|
|
28 |
|
|
29 |
const QString KText("text");
|
|
30 |
const QString KAdditionalText("additionalText");
|
|
31 |
const QString KHexUsageIdFormat("0x%1");
|
|
32 |
const int KHexFieldWidth = 8;
|
|
33 |
const int KHexBase = 16;
|
|
34 |
|
|
35 |
|
|
36 |
// ======== MEMBER FUNCTIONS ========
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// AdvSecSettingsCertTrustSettingsView::AdvSecSettingsCertTrustSettingsView()
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
AdvSecSettingsCertTrustSettingsView::AdvSecSettingsCertTrustSettingsView(
|
|
43 |
AdvSecSettingsCertificateModel &model, QGraphicsItem *parent) :
|
|
44 |
AdvSecSettingsViewBase(0, parent), mModel(model), mCertificate(0),
|
|
45 |
mIsCertDeletable(false), mViewLabel(0), mDataForm(0), mDataFormModel(0)
|
|
46 |
{
|
|
47 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
48 |
|
|
49 |
mViewLabel = new HbGroupBox;
|
|
50 |
layout->addItem(mViewLabel);
|
|
51 |
|
|
52 |
HbScrollArea *scrollArea = new HbScrollArea;
|
|
53 |
mDataForm = new HbDataForm;
|
|
54 |
scrollArea->setContentWidget(mDataForm);
|
|
55 |
layout->addItem(scrollArea);
|
|
56 |
|
|
57 |
setLayout(layout);
|
|
58 |
|
|
59 |
connect(&mModel, SIGNAL(getTrustSettingsCompleted()), this, SLOT(refreshDisplay()));
|
|
60 |
connect(&mModel, SIGNAL(deleteCertificateCompleted()), this, SLOT(close()));
|
|
61 |
connect(this, SIGNAL(aboutToClose()), this, SLOT(saveTrustSettings()));
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
// AdvSecSettingsCertTrustSettingsView::~AdvSecSettingsCertTrustSettingsView()
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
AdvSecSettingsCertTrustSettingsView::~AdvSecSettingsCertTrustSettingsView()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
// AdvSecSettingsCertTrustSettingsView::setCertificate()
|
|
74 |
// ---------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
void AdvSecSettingsCertTrustSettingsView::setCertificate(const AdvSecSettingsCertificate &cert)
|
|
77 |
{
|
|
78 |
mCertificate = &cert;
|
|
79 |
mIsCertDeletable = mModel.isDeletable(cert);
|
|
80 |
|
|
81 |
menu()->clearActions();
|
|
82 |
if (mIsCertDeletable) {
|
|
83 |
HbAction *deleteAction = new HbAction(hbTrId("txt_common_menu_delete"));
|
|
84 |
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteCertificate()));
|
|
85 |
menu()->addAction(deleteAction);
|
|
86 |
}
|
|
87 |
|
|
88 |
mUsageIdAndTrust.clear();
|
|
89 |
mModel.getTrustSettings(cert, mUsageIdAndTrust);
|
|
90 |
}
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// AdvSecSettingsCertTrustSettingsView::refreshDisplay()
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
void AdvSecSettingsCertTrustSettingsView::refreshDisplay()
|
|
97 |
{
|
|
98 |
if (mDataFormModel) {
|
|
99 |
mDataForm->setModel(0);
|
|
100 |
delete mDataFormModel;
|
|
101 |
mDataFormModel = 0;
|
|
102 |
}
|
|
103 |
mDataFormModel = new HbDataFormModel(this);
|
|
104 |
|
|
105 |
QMapIterator<int,bool> iter(mUsageIdAndTrust);
|
|
106 |
while (iter.hasNext()) {
|
|
107 |
iter.next();
|
|
108 |
HbDataFormModelItem *item = mDataFormModel->appendDataFormItem(
|
|
109 |
HbDataFormModelItem::ToggleValueItem, usageName(iter.key()));
|
|
110 |
if (iter.value()) {
|
|
111 |
// TODO: localized UI string needed
|
|
112 |
item->setContentWidgetData(KText, tr("On"));
|
|
113 |
item->setContentWidgetData(KAdditionalText, tr("Off"));
|
|
114 |
} else {
|
|
115 |
// TODO: localized UI string needed
|
|
116 |
item->setContentWidgetData(KText, tr("Off"));
|
|
117 |
item->setContentWidgetData(KAdditionalText, tr("On"));
|
|
118 |
}
|
|
119 |
if (!mIsCertDeletable) {
|
|
120 |
item->setEnabled(false);
|
|
121 |
}
|
|
122 |
}
|
|
123 |
connect(mDataFormModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
|
124 |
this, SLOT(toggleChange(QModelIndex)));
|
|
125 |
|
|
126 |
mViewLabel->setHeading(mCertificate->label());
|
|
127 |
mDataForm->setModel(mDataFormModel);
|
|
128 |
}
|
|
129 |
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
// AdvSecSettingsCertTrustSettingsView::toggleChange()
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void AdvSecSettingsCertTrustSettingsView::toggleChange(const QModelIndex &itemIndex)
|
|
135 |
{
|
|
136 |
if (mIsCertDeletable) {
|
|
137 |
HbDataFormModelItem *item = mDataFormModel->itemFromIndex(itemIndex);
|
|
138 |
|
|
139 |
int usageId = 0;
|
|
140 |
QString label = item->label();
|
|
141 |
QMapIterator<int,QString> iter(mUsageIdAndName);
|
|
142 |
while (iter.hasNext() && !usageId) {
|
|
143 |
iter.next();
|
|
144 |
if (label == iter.value()) {
|
|
145 |
usageId = iter.key();
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
if (usageId) {
|
|
150 |
QVariant data = item->contentWidgetData(KText);
|
|
151 |
if (data.toString() == tr("On")) { // TODO: use localized UI string
|
|
152 |
mUsageIdAndTrust[usageId] = true;
|
|
153 |
} else {
|
|
154 |
mUsageIdAndTrust[usageId] = false;
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
// AdvSecSettingsCertTrustSettingsView::saveTrustSettings()
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void AdvSecSettingsCertTrustSettingsView::saveTrustSettings()
|
|
165 |
{
|
|
166 |
if (mIsCertDeletable) {
|
|
167 |
Q_ASSERT(mCertificate != 0);
|
|
168 |
mModel.setTrustSettings(*mCertificate, mUsageIdAndTrust);
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
// AdvSecSettingsCertTrustSettingsView::deleteCertificate()
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
void AdvSecSettingsCertTrustSettingsView::deleteCertificate()
|
|
177 |
{
|
|
178 |
Q_ASSERT(mCertificate != 0);
|
|
179 |
// TODO: localized UI string needed
|
|
180 |
QString confirmText(tr("Delete %1?").arg(mCertificate->label()));
|
|
181 |
displayQuestionNote(confirmText, this, SLOT(deleteConfirmationAccepted()));
|
|
182 |
}
|
|
183 |
|
|
184 |
// ---------------------------------------------------------------------------
|
|
185 |
// AdvSecSettingsCertTrustSettingsView::deleteConfirmationAccepted()
|
|
186 |
// ---------------------------------------------------------------------------
|
|
187 |
//
|
|
188 |
void AdvSecSettingsCertTrustSettingsView::deleteConfirmationAccepted()
|
|
189 |
{
|
|
190 |
Q_ASSERT(mCertificate != 0);
|
|
191 |
mModel.deleteCertificate(*mCertificate);
|
|
192 |
}
|
|
193 |
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
// AdvSecSettingsCertTrustSettingsView::usageName()
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
QString AdvSecSettingsCertTrustSettingsView::usageName(int usageId)
|
|
199 |
{
|
|
200 |
if (mUsageIdAndName.isEmpty()) {
|
|
201 |
mModel.getCertificateUsageNames(mUsageIdAndName);
|
|
202 |
}
|
|
203 |
|
|
204 |
QString name;
|
|
205 |
if (mUsageIdAndName.contains(usageId)) {
|
|
206 |
name = mUsageIdAndName.value(usageId);
|
|
207 |
} else {
|
|
208 |
name = QString(KHexUsageIdFormat).arg(usageId, KHexFieldWidth, KHexBase);
|
|
209 |
}
|
|
210 |
return name;
|
|
211 |
}
|
|
212 |
|