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 list view in advanced security settings
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "advsecsettingscertificatelistview.h"
|
|
19 |
#include "advsecsettingscertificatemodel.h"
|
|
20 |
#include "advsecsettingscertificatedetailview.h"
|
|
21 |
#include "advsecsettingscerttrustsettingsview.h"
|
|
22 |
#include <QGraphicsLinearLayout>
|
|
23 |
#include <HbAbstractViewItem>
|
|
24 |
#include <HbGroupBox>
|
|
25 |
#include <HbListWidget>
|
|
26 |
#include <HbListWidgetItem>
|
|
27 |
#include <HbLabel>
|
|
28 |
#include <HbStackedWidget>
|
|
29 |
|
|
30 |
|
|
31 |
// ======== MEMBER FUNCTIONS ========
|
|
32 |
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
// AdvSecSettingsCertificateListView::AdvSecSettingsCertificateListView()
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
//
|
|
37 |
AdvSecSettingsCertificateListView::AdvSecSettingsCertificateListView(
|
|
38 |
QGraphicsItem *parent) : AdvSecSettingsViewBase(0, parent),
|
|
39 |
mCertType(AdvSecSettingsCertificate::NotDefined),
|
|
40 |
mListWidget(0), mEmptyText(0), mRetrievingText(0), mStackedWidget(0),
|
|
41 |
mIsRetrieving(true), mModelCertificateList(), mDisplayedCertificates(),
|
|
42 |
mModel(0), mDetailView(), mTrustSettingsView(0), mCurrentCertificate(0)
|
|
43 |
{
|
|
44 |
mModel = new AdvSecSettingsCertificateModel(this);
|
|
45 |
mModel->initialize();
|
|
46 |
connect(mModel, SIGNAL(initializeCompleted()),
|
|
47 |
this, SLOT(readAllCertificatesFromModel()));
|
|
48 |
connect(mModel, SIGNAL(getCertificatesCompleted()),
|
|
49 |
this, SLOT(displayAllCertificatesReadFromModel()));
|
|
50 |
connect(mModel, SIGNAL(deleteCertificateCompleted()),
|
|
51 |
this, SLOT(refreshAfterCurrentCertRemoved()));
|
|
52 |
connect(mModel, SIGNAL(moveToPersonalCertificatesCompleted()),
|
|
53 |
this, SLOT(refreshAfterCurrentCertRemoved()));
|
|
54 |
connect(mModel, SIGNAL(moveToDeviceCertificatesCompleted()),
|
|
55 |
this, SLOT(refreshAfterCurrentCertRemoved()));
|
|
56 |
connect(mModel, SIGNAL(errorOccurred(int)),
|
|
57 |
this, SLOT(displayError(int)));
|
|
58 |
|
|
59 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
60 |
|
|
61 |
// View title
|
|
62 |
mViewLabel = new HbGroupBox;
|
|
63 |
layout->addItem(mViewLabel);
|
|
64 |
|
|
65 |
// Certificate list or empty text
|
|
66 |
mStackedWidget = new HbStackedWidget;
|
|
67 |
|
|
68 |
mListWidget = new HbListWidget;
|
|
69 |
connect(mListWidget, SIGNAL(activated(QModelIndex)),
|
|
70 |
this, SLOT(openCertificate(QModelIndex)));
|
|
71 |
connect(mListWidget, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
|
|
72 |
this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF)));
|
|
73 |
mStackedWidget->addWidget(mListWidget);
|
|
74 |
|
|
75 |
// TODO: localized UI string needed
|
|
76 |
mEmptyText = new HbLabel(tr("No certificates"));
|
|
77 |
mEmptyText->setAlignment(Qt::AlignCenter);
|
|
78 |
mStackedWidget->addWidget(mEmptyText);
|
|
79 |
|
|
80 |
mRetrievingText = new HbLabel(tr("Retrieving..."));
|
|
81 |
mRetrievingText->setAlignment(Qt::AlignCenter);
|
|
82 |
mStackedWidget->addWidget(mRetrievingText);
|
|
83 |
|
|
84 |
mStackedWidget->setCurrentWidget(mRetrievingText);
|
|
85 |
layout->addItem(mStackedWidget);
|
|
86 |
|
|
87 |
setLayout(layout);
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
// AdvSecSettingsCertificateListView::~AdvSecSettingsCertificateListView()
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
AdvSecSettingsCertificateListView::~AdvSecSettingsCertificateListView()
|
|
95 |
{
|
|
96 |
clearModelCertificates();
|
|
97 |
}
|
|
98 |
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
// AdvSecSettingsCertificateListView::displayCertificates()
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
void AdvSecSettingsCertificateListView::displayCertificates(
|
|
104 |
AdvSecSettingsCertificate::CertificateType type)
|
|
105 |
{
|
|
106 |
if (type != mCertType) {
|
|
107 |
mCertType = type;
|
|
108 |
switch (mCertType) {
|
|
109 |
case AdvSecSettingsCertificate::AuthorityCertificate:
|
|
110 |
mViewLabel->setHeading(hbTrId("txt_certificate_manager_subhead_authority_certific"));
|
|
111 |
break;
|
|
112 |
case AdvSecSettingsCertificate::TrustedSiteCertificate:
|
|
113 |
mViewLabel->setHeading(hbTrId("txt_certificate_manager_subhead_trusted_site_certi"));
|
|
114 |
break;
|
|
115 |
case AdvSecSettingsCertificate::PersonalCertificate:
|
|
116 |
mViewLabel->setHeading(hbTrId("txt_certificate_manager_subhead_personal_certifica"));
|
|
117 |
break;
|
|
118 |
case AdvSecSettingsCertificate::DeviceCertificate:
|
|
119 |
mViewLabel->setHeading(hbTrId("txt_certificate_manager_subhead_device_certificate"));
|
|
120 |
break;
|
|
121 |
default:
|
|
122 |
break;
|
|
123 |
}
|
|
124 |
}
|
|
125 |
refreshDisplayedCertificates();
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
// AdvSecSettingsCertificateListView::setCurrentIndex()
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
void AdvSecSettingsCertificateListView::setCurrentIndex(const QModelIndex& index)
|
|
133 |
{
|
|
134 |
mListWidget->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
|
|
135 |
}
|
|
136 |
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
// AdvSecSettingsCertificateListView::indicateLongPress()
|
|
139 |
// ---------------------------------------------------------------------------
|
|
140 |
//
|
|
141 |
void AdvSecSettingsCertificateListView::indicateLongPress(
|
|
142 |
HbAbstractViewItem *item, const QPointF &position)
|
|
143 |
{
|
|
144 |
Q_ASSERT(item != 0);
|
|
145 |
mCurrentCertificate = mDisplayedCertificates.at(item->modelIndex().row());
|
|
146 |
|
|
147 |
clearItemSpecificMenu();
|
|
148 |
addItemSpecificMenuAction(hbTrId("txt_common_menu_open"),
|
|
149 |
this, SLOT(openCurrentCertificate()));
|
|
150 |
|
|
151 |
switch (mCertType) {
|
|
152 |
case AdvSecSettingsCertificate::AuthorityCertificate:
|
|
153 |
addItemSpecificMenuAction(hbTrId("txt_certificate_manager_menu_trust_settings"),
|
|
154 |
this, SLOT(displayCurrentCertTrustSettings()));
|
|
155 |
break;
|
|
156 |
case AdvSecSettingsCertificate::TrustedSiteCertificate:
|
|
157 |
break;
|
|
158 |
case AdvSecSettingsCertificate::PersonalCertificate:
|
|
159 |
addItemSpecificMenuAction(hbTrId("txt_certificate_manager_menu_move_to_device_certif"),
|
|
160 |
this, SLOT(moveCurrentCertToDeviceCertificates()));
|
|
161 |
break;
|
|
162 |
case AdvSecSettingsCertificate::DeviceCertificate:
|
|
163 |
addItemSpecificMenuAction(hbTrId("txt_certificate_manager_menu_move_to_personal_cert"),
|
|
164 |
this, SLOT(moveCurrentCertToPersonalCertificates()));
|
|
165 |
break;
|
|
166 |
default:
|
|
167 |
break;
|
|
168 |
}
|
|
169 |
|
|
170 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
171 |
if (mModel->isDeletable(*mCurrentCertificate)) {
|
|
172 |
addItemSpecificMenuAction(hbTrId("txt_common_menu_delete"),
|
|
173 |
this, SLOT(deleteCurrentCertificate()));
|
|
174 |
}
|
|
175 |
|
|
176 |
displayItemSpecificMenu(position);
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
// AdvSecSettingsCertificateListView::openCertificate()
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
//
|
|
183 |
void AdvSecSettingsCertificateListView::openCertificate(const QModelIndex& modelIndex)
|
|
184 |
{
|
|
185 |
mCurrentCertificate = mDisplayedCertificates.at(modelIndex.row());
|
|
186 |
openCurrentCertificate();
|
|
187 |
}
|
|
188 |
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
// AdvSecSettingsCertificateListView::openCurrentCertificate()
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
void AdvSecSettingsCertificateListView::openCurrentCertificate()
|
|
194 |
{
|
|
195 |
if (!mDetailView) {
|
|
196 |
mDetailView = new AdvSecSettingsCertificateDetailView(*mModel, this);
|
|
197 |
}
|
|
198 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
199 |
mDetailView->setCertificate(*mCurrentCertificate);
|
|
200 |
displayView(mDetailView);
|
|
201 |
}
|
|
202 |
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// AdvSecSettingsCertificateListView::displayCurrentCertTrustSettings()
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void AdvSecSettingsCertificateListView::displayCurrentCertTrustSettings()
|
|
208 |
{
|
|
209 |
if (!mTrustSettingsView) {
|
|
210 |
mTrustSettingsView = new AdvSecSettingsCertTrustSettingsView(*mModel, this);
|
|
211 |
}
|
|
212 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
213 |
mTrustSettingsView->setCertificate(*mCurrentCertificate);
|
|
214 |
displayView(mTrustSettingsView);
|
|
215 |
}
|
|
216 |
|
|
217 |
// ---------------------------------------------------------------------------
|
|
218 |
// AdvSecSettingsCertificateListView::deleteCurrentCertificate()
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
void AdvSecSettingsCertificateListView::deleteCurrentCertificate()
|
|
222 |
{
|
|
223 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
224 |
// TODO: localized UI string needed
|
|
225 |
QString confirmText(tr("Delete %1?").arg(mCurrentCertificate->label()));
|
|
226 |
displayQuestionNote(confirmText, this, SLOT(deleteConfirmationAccepted()));
|
|
227 |
}
|
|
228 |
|
|
229 |
// ---------------------------------------------------------------------------
|
|
230 |
// AdvSecSettingsCertificateListView::deleteConfirmationAccepted()
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
void AdvSecSettingsCertificateListView::deleteConfirmationAccepted()
|
|
234 |
{
|
|
235 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
236 |
mModel->deleteCertificate(*mCurrentCertificate);
|
|
237 |
}
|
|
238 |
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
// AdvSecSettingsCertificateListView::moveCurrentCertToDeviceCertificates()
|
|
241 |
// ---------------------------------------------------------------------------
|
|
242 |
//
|
|
243 |
void AdvSecSettingsCertificateListView::moveCurrentCertToDeviceCertificates()
|
|
244 |
{
|
|
245 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
246 |
QString confirmText(hbTrId("txt_certificate_info_device_certificates_can_be_us"));
|
|
247 |
displayQuestionNote(confirmText, this, SLOT(moveToDeviceCertsConfirmationAccepted()));
|
|
248 |
}
|
|
249 |
|
|
250 |
// ---------------------------------------------------------------------------
|
|
251 |
// AdvSecSettingsCertificateListView::moveToDeviceCertsConfirmationAccepted()
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
void AdvSecSettingsCertificateListView::moveToDeviceCertsConfirmationAccepted()
|
|
255 |
{
|
|
256 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
257 |
mModel->moveToDeviceCertificates(*mCurrentCertificate);
|
|
258 |
}
|
|
259 |
|
|
260 |
// ---------------------------------------------------------------------------
|
|
261 |
// AdvSecSettingsCertificateListView::moveCurrentCertToPersonalCertificates()
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void AdvSecSettingsCertificateListView::moveCurrentCertToPersonalCertificates()
|
|
265 |
{
|
|
266 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
267 |
// TODO: localized UI string needed
|
|
268 |
QString confirmText(tr("Using personal certificates may require user confirmation. Continue?"));
|
|
269 |
displayQuestionNote(confirmText, this, SLOT(moveToPersonalCertsConfirmationAccepted()));
|
|
270 |
}
|
|
271 |
|
|
272 |
// ---------------------------------------------------------------------------
|
|
273 |
// AdvSecSettingsCertificateListView::moveToPersonalCertsConfirmationAccepted()
|
|
274 |
// ---------------------------------------------------------------------------
|
|
275 |
//
|
|
276 |
void AdvSecSettingsCertificateListView::moveToPersonalCertsConfirmationAccepted()
|
|
277 |
{
|
|
278 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
279 |
mModel->moveToPersonalCertificates(*mCurrentCertificate);
|
|
280 |
}
|
|
281 |
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
// AdvSecSettingsCertificateListView::readAllCertificatesFromModel()
|
|
284 |
// ---------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
void AdvSecSettingsCertificateListView::readAllCertificatesFromModel()
|
|
287 |
{
|
|
288 |
clearModelCertificates();
|
|
289 |
mModel->getCertificates(mModelCertificateList);
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
// AdvSecSettingsCertificateListView::displayAllCertificatesReadFromModel()
|
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
void AdvSecSettingsCertificateListView::displayAllCertificatesReadFromModel()
|
|
297 |
{
|
|
298 |
if (mCertType != AdvSecSettingsCertificate::NotDefined) {
|
|
299 |
mIsRetrieving = false;
|
|
300 |
refreshDisplayedCertificates();
|
|
301 |
}
|
|
302 |
}
|
|
303 |
|
|
304 |
// ---------------------------------------------------------------------------
|
|
305 |
// AdvSecSettingsCertificateListView::clearModelCertificates()
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
void AdvSecSettingsCertificateListView::clearModelCertificates()
|
|
309 |
{
|
|
310 |
if (!mModelCertificateList.isEmpty()) {
|
|
311 |
QMutableListIterator<AdvSecSettingsCertificate *> iter(mModelCertificateList);
|
|
312 |
while (iter.hasNext()) {
|
|
313 |
delete iter.next();
|
|
314 |
}
|
|
315 |
mModelCertificateList.clear();
|
|
316 |
}
|
|
317 |
mCurrentCertificate = 0;
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
// AdvSecSettingsCertificateListView::refreshDisplayedCertificates()
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
void AdvSecSettingsCertificateListView::refreshDisplayedCertificates()
|
|
325 |
{
|
|
326 |
int currentRow = mListWidget->currentRow();
|
|
327 |
mListWidget->clear();
|
|
328 |
mDisplayedCertificates.clear();
|
|
329 |
QListIterator<AdvSecSettingsCertificate *> iter(mModelCertificateList);
|
|
330 |
while (iter.hasNext()) {
|
|
331 |
AdvSecSettingsCertificate *cert = iter.next();
|
|
332 |
if (cert->certType() == mCertType) {
|
|
333 |
mDisplayedCertificates.append(cert);
|
|
334 |
HbListWidgetItem *item = new HbListWidgetItem;
|
|
335 |
item->setText(cert->label());
|
|
336 |
mListWidget->addItem(item);
|
|
337 |
}
|
|
338 |
}
|
|
339 |
if (mListWidget->count()) {
|
|
340 |
if (currentRow < mListWidget->count()) {
|
|
341 |
mListWidget->setCurrentRow(currentRow);
|
|
342 |
}
|
|
343 |
mStackedWidget->setCurrentWidget(mListWidget);
|
|
344 |
} else {
|
|
345 |
if (mIsRetrieving) {
|
|
346 |
mStackedWidget->setCurrentWidget(mRetrievingText);
|
|
347 |
} else {
|
|
348 |
mStackedWidget->setCurrentWidget(mEmptyText);
|
|
349 |
}
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
// AdvSecSettingsCertificateListView::refreshAfterCurrentCertRemoved()
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
//
|
|
357 |
void AdvSecSettingsCertificateListView::refreshAfterCurrentCertRemoved()
|
|
358 |
{
|
|
359 |
Q_ASSERT(mCurrentCertificate != 0);
|
|
360 |
|
|
361 |
QString currentCertLabel = mCurrentCertificate->label();
|
|
362 |
for (TInt row = 0; row < mListWidget->count(); row++) {
|
|
363 |
HbListWidgetItem *item = mListWidget->item(row);
|
|
364 |
if (item->text() == currentCertLabel) {
|
|
365 |
item = mListWidget->takeItem(row);
|
|
366 |
delete item;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
if (mListWidget->count()) {
|
|
370 |
mStackedWidget->setCurrentWidget(mListWidget);
|
|
371 |
} else {
|
|
372 |
mStackedWidget->setCurrentWidget(mEmptyText);
|
|
373 |
}
|
|
374 |
|
|
375 |
mDisplayedCertificates.removeAll(mCurrentCertificate);
|
|
376 |
mCurrentCertificate = 0;
|
|
377 |
|
|
378 |
readAllCertificatesFromModel();
|
|
379 |
}
|
|
380 |
|