|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStringList> |
|
19 #include <QGraphicsLinearLayout> |
|
20 #include <QModelIndex> |
|
21 |
|
22 #include <hblineedit.h> |
|
23 #include <hbdataform.h> |
|
24 #include <hbdataformmodel.h> |
|
25 #include <hbdataformmodelitem.h> |
|
26 #include <hblabel.h> |
|
27 #include <hbpushbutton.h> |
|
28 #include <HbMenu.h> |
|
29 #include <hbaction.h> |
|
30 #include <HbListWidget> |
|
31 #include <HbListWidgetItem> |
|
32 #include <HbGroupBox> |
|
33 #include <hbpushbutton.h> |
|
34 #include <hbdataform.h> |
|
35 #include <hbdataformmodel.h> |
|
36 #include <hbdataformmodelitem.h> |
|
37 #include <hbabstractviewitem.h> |
|
38 #include <hbtextitem.h> |
|
39 #include <hbmainwindow.h> |
|
40 #include <HbListView.h> |
|
41 #include <QStandardItemModel> |
|
42 #include <QModelIndexList> |
|
43 #include <hbmessagebox.h> |
|
44 #include <memory> |
|
45 |
|
46 #include "cpcertdetailview.h" |
|
47 #include "cpcertview.h" |
|
48 #include "cpcertdatacontainer.h" |
|
49 #include "cpcerttrustview.h" |
|
50 #include "cpcertmanuisyncwrapper.h" |
|
51 |
|
52 |
|
53 CpCertView::CpCertView(const QModelIndex& modelIndex, QGraphicsItem *parent /*= 0*/) |
|
54 : CpBaseSettingView(0,parent), |
|
55 mPrevView(NULL), |
|
56 mCurrentView(NULL), |
|
57 mRefreshedView(NULL), |
|
58 mListView(NULL), |
|
59 mOriginalView(NULL) |
|
60 { |
|
61 |
|
62 mOriginalView = mainWindow()->currentView(); |
|
63 |
|
64 HbMenu* menu = this->menu(); |
|
65 std::auto_ptr<HbAction> deleteAction(new HbAction(hbTrId("txt_common_menu_delete"))); |
|
66 connect(deleteAction.get(), SIGNAL(triggered()), this, SLOT(deleteList())); |
|
67 menu->addAction(deleteAction.get()); |
|
68 deleteAction.release(); |
|
69 |
|
70 std::auto_ptr<QGraphicsLinearLayout> layout(new QGraphicsLinearLayout(Qt::Vertical)); |
|
71 |
|
72 HbDataForm *form = q_check_ptr(new HbDataForm(this)); |
|
73 std::auto_ptr<HbDataFormModel> formModel(q_check_ptr(new HbDataFormModel())); |
|
74 form->setModel(formModel.get()); |
|
75 formModel.release(); |
|
76 |
|
77 HbListWidget* certificateList = q_check_ptr(new HbListWidget(this)); |
|
78 |
|
79 CpCertView::TCertificateViews currentView = (CpCertView::TCertificateViews)modelIndex.row(); |
|
80 QString title; |
|
81 if(currentView == EPersonalView) |
|
82 { |
|
83 title = "Move to Device"; |
|
84 } |
|
85 else if(currentView == EDeviceView) |
|
86 { |
|
87 title = "Move to Personal"; |
|
88 } |
|
89 std::auto_ptr<HbAction> moveToDeviceAction(q_check_ptr(new HbAction(title))); |
|
90 connect(moveToDeviceAction.get(), SIGNAL(triggered()), this, SLOT(moveCert())); |
|
91 menu->addAction(moveToDeviceAction.get()); |
|
92 moveToDeviceAction.release(); |
|
93 |
|
94 setDetails(currentView); |
|
95 TInt count = 0; |
|
96 try |
|
97 { |
|
98 QT_TRAP_THROWING(mCertDataContainer = CpCertDataContainer::NewL()); |
|
99 QT_TRAP_THROWING(count = refreshListL()); |
|
100 } |
|
101 catch(const std::exception& exception) |
|
102 { |
|
103 HbMessageBox::information(exception.what()); |
|
104 throw(exception); |
|
105 } |
|
106 |
|
107 for(int index = 0; index< count; index++) |
|
108 { |
|
109 QString certificateLabel = certLabel(index); |
|
110 std::auto_ptr<HbListWidgetItem> singleCert(q_check_ptr(new HbListWidgetItem())); |
|
111 singleCert->setText(certificateLabel); |
|
112 certificateList->addItem(singleCert.get()); |
|
113 singleCert.release(); |
|
114 } // End of FOR loop |
|
115 |
|
116 connect(certificateList, SIGNAL(activated(QModelIndex)), this, SLOT(openCertFromList(QModelIndex))); |
|
117 connect(certificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); |
|
118 |
|
119 layout->addItem(certificateList); |
|
120 setLayout(layout.get()); |
|
121 layout.release(); |
|
122 } |
|
123 |
|
124 CpCertView::~CpCertView() |
|
125 { |
|
126 delete mCertDataContainer; |
|
127 mCertDataContainer = NULL; |
|
128 |
|
129 if(mPrevView) |
|
130 { |
|
131 mPrevView->deleteLater(); |
|
132 mPrevView= NULL; |
|
133 } |
|
134 if(mCurrentView) |
|
135 { |
|
136 mCurrentView->deleteLater(); |
|
137 mCurrentView= NULL; |
|
138 } |
|
139 if(mRefreshedView) |
|
140 { |
|
141 mRefreshedView->deleteLater(); |
|
142 mRefreshedView= NULL; |
|
143 } |
|
144 if(mListView) |
|
145 { |
|
146 mListView->deleteLater(); |
|
147 mListView= NULL; |
|
148 } |
|
149 } |
|
150 |
|
151 void CpCertView::setDetails(CpCertView::TCertificateViews currentView) |
|
152 { |
|
153 switch(currentView) |
|
154 { |
|
155 case EAuthorityView: |
|
156 setTitle(hbTrId("txt_certificate_manager_list_authority_certificate")); |
|
157 mCertView = EAuthorityView; |
|
158 break; |
|
159 |
|
160 case ETrustedView: |
|
161 setTitle(hbTrId("txt_certificate_manager_list_trusted_site_certific")); |
|
162 mCertView = ETrustedView; |
|
163 break; |
|
164 |
|
165 case EPersonalView: |
|
166 setTitle(hbTrId("txt_certificate_manager_list_personal_certificates")); |
|
167 mCertView = EPersonalView; |
|
168 break; |
|
169 |
|
170 case EDeviceView: |
|
171 setTitle(hbTrId("txt_certificate_manager_list_device_certificates")); |
|
172 mCertView = EDeviceView; |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 void CpCertView::indicateLongPress(HbAbstractViewItem *item,QPointF coords) |
|
178 { |
|
179 std::auto_ptr<HbMenu> contextMenu(q_check_ptr(new HbMenu())); |
|
180 mPos = item->modelIndex().row(); // Pos will tell you what is the certificate clicked in particular view. |
|
181 |
|
182 std::auto_ptr<HbAction> open(q_check_ptr(new HbAction(hbTrId("txt_common_menu_open")))); |
|
183 connect(open.get(), SIGNAL(triggered()), this, SLOT( openCertificate())); |
|
184 contextMenu->addAction(open.get()); |
|
185 open.release(); |
|
186 |
|
187 QString moveTitle; |
|
188 |
|
189 if(mCertView == EAuthorityView) |
|
190 { |
|
191 std::auto_ptr<HbAction> trustSettings(q_check_ptr(new HbAction(hbTrId("txt_certificate_manager_menu_trust_settings")))); |
|
192 connect(trustSettings.get(), SIGNAL(triggered()), this, SLOT(showTrustSettings())); |
|
193 contextMenu->addAction(trustSettings.get()); |
|
194 trustSettings.release(); |
|
195 } |
|
196 else if(mCertView == EPersonalView) |
|
197 { |
|
198 moveTitle = hbTrId("txt_certificate_manager_menu_move_to_device_certif"); |
|
199 } |
|
200 else if(mCertView == EDeviceView) |
|
201 { |
|
202 moveTitle = hbTrId("txt_certificate_manager_menu_move_to_personal_cert"); |
|
203 } |
|
204 std::auto_ptr<HbAction> moveCert(q_check_ptr(new HbAction(moveTitle))); |
|
205 connect(moveCert.get(), SIGNAL(triggered()), this, SLOT(moveSelectedCert())); |
|
206 contextMenu->addAction(moveCert.get()); |
|
207 moveCert.release(); |
|
208 |
|
209 if( certAt(mPos)->IsDeletable() ) |
|
210 { |
|
211 std::auto_ptr<HbAction> menuDelete(q_check_ptr(new HbAction(hbTrId("txt_common_menu_delete")))); |
|
212 connect(menuDelete.get(), SIGNAL(triggered()), this, SLOT(deleteCertificate())); |
|
213 contextMenu->addAction(menuDelete.get()); |
|
214 menuDelete.release(); |
|
215 } |
|
216 contextMenu->open(); |
|
217 contextMenu->setPreferredPos(coords); |
|
218 } |
|
219 |
|
220 void CpCertView::openCertFromList(const QModelIndex& modelIndex) |
|
221 { |
|
222 // Pos will tell you what is the certificate clicked in particular view. |
|
223 mPos = modelIndex.row(); |
|
224 openCertificate(); |
|
225 } |
|
226 |
|
227 void CpCertView::openCertificate() |
|
228 { |
|
229 mCurrentView = q_check_ptr(new CpCertDetailView(mCertView,mPos,*mCertDataContainer)); |
|
230 connect(mCurrentView, SIGNAL(aboutToClose()), this, SLOT(displayPreviousView())); |
|
231 mPrevView = mainWindow()->currentView(); |
|
232 mainWindow()->addView(mCurrentView); |
|
233 mainWindow()->setCurrentView(mCurrentView); |
|
234 } |
|
235 |
|
236 void CpCertView::displayPreviousView() |
|
237 { |
|
238 mainWindow()->removeView(mCurrentView); |
|
239 mCurrentView->deleteLater(); |
|
240 mCurrentView= NULL; |
|
241 mainWindow()->setCurrentView(mPrevView); |
|
242 } |
|
243 |
|
244 void CpCertView::deleteCertificate() |
|
245 { |
|
246 RArray<TInt> pos; |
|
247 pos.Append(mPos); |
|
248 QT_TRAP_THROWING(deleteCerts(pos)); |
|
249 } |
|
250 |
|
251 void CpCertView::deleteList() |
|
252 { |
|
253 mSelectAll = EFalse; |
|
254 HbDialog popup; |
|
255 popup.setDismissPolicy(HbDialog::NoDismiss); |
|
256 // Set the label as heading widget |
|
257 popup.setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_setlabel_certificates")))); |
|
258 |
|
259 std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical))); |
|
260 |
|
261 HbListView* selectAllView = q_check_ptr(new HbListView(this)); |
|
262 QStandardItemModel* selectAllModel = q_check_ptr(new QStandardItemModel(this)); |
|
263 // Populate the model with content |
|
264 std::auto_ptr<QStandardItem> selectAllItem(q_check_ptr(new QStandardItem())); |
|
265 selectAllItem->setData(QString("Select All"),Qt::DisplayRole); |
|
266 selectAllModel->appendRow(selectAllItem.get()); |
|
267 selectAllItem.release(); |
|
268 |
|
269 connect(selectAllView, SIGNAL(activated(QModelIndex)), this, SLOT(selectAll())); |
|
270 selectAllView->setModel(selectAllModel); |
|
271 selectAllView->setSelectionMode(HbListView::MultiSelection); |
|
272 layout->addItem(selectAllView); |
|
273 |
|
274 mListView = q_check_ptr(new HbListView(this)); |
|
275 // Connect to "activated" signal |
|
276 connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex))); |
|
277 |
|
278 // Create a model |
|
279 QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this)); |
|
280 TInt count=0; |
|
281 QT_TRAP_THROWING( count = refreshListL()); |
|
282 RArray<TInt> selectionIndex; |
|
283 QT_TRAP_THROWING(CleanupClosePushL(selectionIndex)); |
|
284 |
|
285 for(TInt index = 0; index < count ; ++index) |
|
286 { |
|
287 const CCTCertInfo* cert = certAt(index); |
|
288 if( cert->IsDeletable() ) |
|
289 { |
|
290 // Populate the model with content |
|
291 std::auto_ptr<QStandardItem> certItem(q_check_ptr(new QStandardItem())); |
|
292 QString certificateLabel = certLabel(index); |
|
293 certItem->setData( certificateLabel, Qt::DisplayRole); |
|
294 model->appendRow(certItem.get()); |
|
295 selectionIndex.Append(index); |
|
296 certItem.release(); |
|
297 } |
|
298 } |
|
299 // Set the model to the list view |
|
300 mListView->setModel(model); |
|
301 mListView->setSelectionMode(HbListView::MultiSelection); |
|
302 layout->addItem(mListView); |
|
303 |
|
304 std::auto_ptr<HbWidget> widget( q_check_ptr(new HbWidget())); |
|
305 widget->setLayout(layout.get()); |
|
306 layout.release(); |
|
307 popup.setContentWidget(widget.get()); |
|
308 widget.release(); |
|
309 |
|
310 popup.setPrimaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete")))); |
|
311 popup.setSecondaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_button_cancel")))); |
|
312 popup.setTimeout(HbPopup::NoTimeout); |
|
313 |
|
314 // Launch popup syncronously |
|
315 HbAction* result = popup.exec(); |
|
316 if(result == popup.primaryAction()) |
|
317 { |
|
318 QItemSelectionModel *selectionModel = mListView->selectionModel(); |
|
319 QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes(); |
|
320 TInt deleteCount = mWidgetItemsToRemove.count(); |
|
321 // start deleting from end of array so that the indexes do not changes of the ones |
|
322 // at the front. |
|
323 RArray<TInt> actualIndex; |
|
324 QT_TRAP_THROWING(CleanupClosePushL(actualIndex)); |
|
325 for (TInt index = deleteCount-1; index>= 0 ; --index) |
|
326 { |
|
327 TInt selectedItemIndex = mWidgetItemsToRemove[index].row(); |
|
328 actualIndex.Append( selectionIndex[selectedItemIndex] ); |
|
329 } |
|
330 deleteCerts(actualIndex); |
|
331 CleanupStack::PopAndDestroy(&actualIndex); |
|
332 } |
|
333 CleanupStack::PopAndDestroy(&selectionIndex); |
|
334 mListView->deleteLater(); |
|
335 mListView = NULL; |
|
336 selectAllView->deleteLater(); |
|
337 selectAllView = NULL; |
|
338 } |
|
339 |
|
340 void CpCertView::moveCert() |
|
341 { |
|
342 mSelectAll = EFalse; |
|
343 HbDialog popup; |
|
344 popup.setDismissPolicy(HbDialog::NoDismiss); |
|
345 // Set the label as heading widget |
|
346 if(mCertView == EPersonalView) |
|
347 { |
|
348 popup.setHeadingWidget(q_check_ptr(new HbLabel(tr("Move To Device")))); |
|
349 } |
|
350 else if(mCertView == EDeviceView) |
|
351 { |
|
352 popup.setHeadingWidget(q_check_ptr(new HbLabel(tr("Move To Personal")))); |
|
353 } |
|
354 |
|
355 std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical))); |
|
356 |
|
357 HbListView* selectAllView = q_check_ptr(new HbListView(this)); |
|
358 QStandardItemModel* selectAllModel = q_check_ptr(new QStandardItemModel(this)); |
|
359 // Populate the model with content |
|
360 std::auto_ptr<QStandardItem> selectAllItem(q_check_ptr(new QStandardItem())); |
|
361 selectAllItem->setData(QString("Select All"),Qt::DisplayRole); |
|
362 selectAllModel->appendRow(selectAllItem.get()); |
|
363 selectAllItem.release(); |
|
364 connect(selectAllView, SIGNAL(activated(QModelIndex)), this, SLOT(selectAll())); |
|
365 selectAllView->setModel(selectAllModel); |
|
366 selectAllView->setSelectionMode(HbListView::MultiSelection); |
|
367 layout->addItem(selectAllView); |
|
368 |
|
369 mListView = q_check_ptr(new HbListView(this)); |
|
370 // Connect to "activated" signal |
|
371 connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex))); |
|
372 |
|
373 // Create a model |
|
374 QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this)); |
|
375 TInt count =0; |
|
376 QT_TRAP_THROWING(count = refreshListL()); |
|
377 RArray<TInt> selectionIndex; |
|
378 QT_TRAP_THROWING(CleanupClosePushL(selectionIndex)); |
|
379 for(TInt index = 0; index < count ; ++index) |
|
380 { |
|
381 // Populate the model with content |
|
382 std::auto_ptr<QStandardItem> certItem(q_check_ptr(new QStandardItem())); |
|
383 QString certificateLabel = certLabel(index); |
|
384 certItem->setData( certificateLabel, Qt::DisplayRole); |
|
385 model->appendRow(certItem.get()); |
|
386 selectionIndex.Append(index); |
|
387 certItem.release(); |
|
388 } |
|
389 |
|
390 // Set the model to the list view |
|
391 mListView->setModel(model); |
|
392 mListView->setSelectionMode(HbListView::MultiSelection); |
|
393 layout->addItem(mListView); |
|
394 |
|
395 std::auto_ptr<HbWidget> widget(q_check_ptr(new HbWidget())); |
|
396 widget->setLayout(layout.get()); |
|
397 layout.release(); |
|
398 popup.setContentWidget(widget.get()); |
|
399 widget.release(); |
|
400 |
|
401 popup.setPrimaryAction(q_check_ptr(new HbAction(tr("Yes"),&popup))); |
|
402 popup.setSecondaryAction(q_check_ptr(new HbAction(tr("No"),&popup))); |
|
403 popup.setTimeout(HbPopup::NoTimeout); |
|
404 |
|
405 // Launch popup syncronously |
|
406 HbAction* result = popup.exec(); |
|
407 if(result == popup.primaryAction()) |
|
408 { |
|
409 QItemSelectionModel *selectionModel = mListView->selectionModel(); |
|
410 QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes(); |
|
411 TInt deleteCount = mWidgetItemsToRemove.count(); |
|
412 // start deleting from end of array so that the indexes do not changes of the ones |
|
413 // at the front. |
|
414 RArray<TInt> actualIndex; |
|
415 QT_TRAP_THROWING(CleanupClosePushL(actualIndex)); |
|
416 for (TInt index = deleteCount-1; index>= 0 ; --index) |
|
417 { |
|
418 TInt selectedItemIndex = mWidgetItemsToRemove[index].row(); |
|
419 actualIndex.Append(selectionIndex[selectedItemIndex]); |
|
420 } |
|
421 moveCertList(actualIndex); |
|
422 CleanupStack::PopAndDestroy(&actualIndex); |
|
423 } |
|
424 CleanupStack::PopAndDestroy(&selectionIndex); |
|
425 mListView->deleteLater(); |
|
426 mListView = NULL; |
|
427 selectAllView->deleteLater(); |
|
428 selectAllView = NULL; |
|
429 } |
|
430 |
|
431 void CpCertView::selectAll() |
|
432 { |
|
433 if(mSelectAll == EFalse) |
|
434 { |
|
435 mListView->selectAll(); |
|
436 mSelectAll= ETrue; |
|
437 } |
|
438 else |
|
439 { |
|
440 mListView->clearSelection(); |
|
441 mSelectAll= EFalse; |
|
442 } |
|
443 } |
|
444 |
|
445 void CpCertView::deleteCerts( RArray<TInt>& indexList ) |
|
446 { |
|
447 TInt count = indexList.Count(); |
|
448 |
|
449 HbMessageBox note(HbMessageBox::MessageTypeQuestion); |
|
450 QString deleteMsg; |
|
451 QString sCount; |
|
452 if(count == 1) |
|
453 { |
|
454 deleteMsg = "Delete %1?"; |
|
455 const CCTCertInfo* entry = certAt(indexList[0]); |
|
456 sCount = QString((QChar*)entry->Label().Ptr(),entry->Label().Length()); |
|
457 } |
|
458 else |
|
459 { |
|
460 deleteMsg = "Delete %1 items?"; |
|
461 sCount.setNum(count); |
|
462 } |
|
463 |
|
464 deleteMsg = deleteMsg.arg(sCount); |
|
465 note.setText(deleteMsg); |
|
466 note.setPrimaryAction(q_check_ptr(new HbAction("Yes"))); |
|
467 note.setSecondaryAction(q_check_ptr(new HbAction("No"))); |
|
468 note.setTimeout(HbPopup::NoTimeout); |
|
469 HbAction* result = note.exec(); |
|
470 |
|
471 if (result != note.primaryAction() || count == 0 ) |
|
472 { |
|
473 return; |
|
474 } |
|
475 |
|
476 RPointerArray<CCTCertInfo> errCerts; |
|
477 QT_TRAP_THROWING(CleanupClosePushL(errCerts)); |
|
478 |
|
479 for(TInt index = 0; index < count; ++index) |
|
480 { |
|
481 const CCTCertInfo* entry = certAt(indexList[index]); |
|
482 |
|
483 if( mCertView == EPersonalView || mCertView == EAuthorityView ) |
|
484 { |
|
485 QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL( |
|
486 mCertDataContainer->CertManager(), *entry )); |
|
487 } |
|
488 else if( mCertView == ETrustedView ) |
|
489 { |
|
490 QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL( |
|
491 mCertDataContainer->CertManager(),*entry, KCMTrustedServerTokenUid )); |
|
492 } |
|
493 else if( mCertView == EDeviceView ) |
|
494 { |
|
495 QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL( |
|
496 mCertDataContainer->CertManager(), *entry, KCMDeviceCertStoreTokenUid )); |
|
497 } |
|
498 QT_TRAP_THROWING( errCerts.AppendL(entry)); |
|
499 } |
|
500 |
|
501 if(errCerts.Count() > 0) |
|
502 { |
|
503 QString message("Unable to delete the following certificate: \n"); |
|
504 TInt count = errCerts.Count(); |
|
505 for(TInt index=0;index<count;++index) |
|
506 { |
|
507 const TDesC& certLabel = errCerts[index]->Label(); |
|
508 QString certName = QString((QChar*)certLabel.Ptr(),certLabel.Length()); |
|
509 message.append(certName).append("\n"); |
|
510 } |
|
511 HbMessageBox::warning(message); |
|
512 } |
|
513 QT_TRAP_THROWING( count = refreshListL()); |
|
514 refreshView(count); |
|
515 |
|
516 CleanupStack::PopAndDestroy(&errCerts); |
|
517 |
|
518 } |
|
519 |
|
520 const CCTCertInfo* CpCertView::certAt(TInt index) const |
|
521 { |
|
522 CCTCertInfo* currentCert = NULL; |
|
523 switch(mCertView) |
|
524 { |
|
525 case EAuthorityView: |
|
526 { |
|
527 currentCert = mCertDataContainer->iCALabelEntries[ index ]->iCAEntry; |
|
528 break; |
|
529 } |
|
530 case ETrustedView: |
|
531 { |
|
532 currentCert = mCertDataContainer->iPeerLabelEntries[ index ]->iPeerEntry; |
|
533 break; |
|
534 } |
|
535 case EDeviceView: |
|
536 { |
|
537 currentCert = mCertDataContainer->iDeviceLabelEntries[ index ]->iDeviceEntry; |
|
538 break; |
|
539 } |
|
540 case EPersonalView: |
|
541 { |
|
542 currentCert = mCertDataContainer->iUserLabelEntries[ index ]->iUserEntry; |
|
543 break; |
|
544 } |
|
545 }; |
|
546 return currentCert; |
|
547 } |
|
548 |
|
549 QString CpCertView::certLabel(TInt index) const |
|
550 { |
|
551 CpCertManUICertData* certData = NULL; |
|
552 HBufC* label = NULL; |
|
553 TInt length = 0; |
|
554 switch(mCertView) |
|
555 { |
|
556 case EAuthorityView: |
|
557 { |
|
558 certData = mCertDataContainer->iCALabelEntries[index]; |
|
559 label = certData->iCAEntryLabel; |
|
560 length = certData->iCAEntryLabel->Length(); |
|
561 break; |
|
562 } |
|
563 case ETrustedView: |
|
564 { |
|
565 certData = mCertDataContainer->iPeerLabelEntries[index]; |
|
566 label = certData->iPeerEntryLabel; |
|
567 length = certData->iPeerEntryLabel->Length(); |
|
568 break; |
|
569 } |
|
570 case EPersonalView: |
|
571 { |
|
572 certData = mCertDataContainer->iUserLabelEntries[index]; |
|
573 label = certData->iUserEntryLabel; |
|
574 length = certData->iUserEntryLabel->Length(); |
|
575 break; |
|
576 } |
|
577 case EDeviceView: |
|
578 { |
|
579 certData = mCertDataContainer->iDeviceLabelEntries[index]; |
|
580 label = certData->iDeviceEntryLabel; |
|
581 length = certData->iDeviceEntryLabel->Length(); |
|
582 break; |
|
583 } |
|
584 } |
|
585 return QString((QChar*)label->Des().Ptr(), length); |
|
586 } |
|
587 |
|
588 TInt CpCertView::refreshListL() |
|
589 { |
|
590 TInt count = 0; |
|
591 switch(mCertView) |
|
592 { |
|
593 case EAuthorityView: |
|
594 mCertDataContainer->RefreshCAEntriesL(); |
|
595 count = mCertDataContainer->iCALabelEntries.Count(); |
|
596 break; |
|
597 case ETrustedView: |
|
598 mCertDataContainer->RefreshPeerCertEntriesL(); |
|
599 count = mCertDataContainer->iPeerLabelEntries.Count(); |
|
600 break; |
|
601 case EPersonalView: |
|
602 mCertDataContainer->RefreshUserCertEntriesL(); |
|
603 count = mCertDataContainer->iUserLabelEntries.Count(); |
|
604 break; |
|
605 case EDeviceView: |
|
606 mCertDataContainer->RefreshDeviceCertEntriesL(); |
|
607 count = mCertDataContainer->iDeviceLabelEntries.Count(); |
|
608 break; |
|
609 }; |
|
610 return count; |
|
611 } |
|
612 |
|
613 |
|
614 void CpCertView::refreshView( TInt count ) |
|
615 { |
|
616 if(mRefreshedView) |
|
617 { |
|
618 mRefreshedView->deleteLater(); |
|
619 mRefreshedView = NULL; |
|
620 } |
|
621 |
|
622 mRefreshedView = q_check_ptr(new CpBaseSettingView()); |
|
623 switch(mCertView) |
|
624 { |
|
625 case EAuthorityView: |
|
626 { |
|
627 mRefreshedView->setTitle(hbTrId("txt_certificate_manager_list_authority_certificate")); |
|
628 break; |
|
629 } |
|
630 case ETrustedView: |
|
631 { |
|
632 mRefreshedView->setTitle(hbTrId("txt_certificate_manager_list_trusted_site_certific")); |
|
633 break; |
|
634 } |
|
635 case EPersonalView: |
|
636 { |
|
637 mRefreshedView->setTitle(hbTrId("txt_certificate_manager_list_personal_certificates")); |
|
638 break; |
|
639 } |
|
640 case EDeviceView: |
|
641 { |
|
642 mRefreshedView->setTitle(hbTrId("txt_certificate_manager_list_device_certificates")); |
|
643 break; |
|
644 } |
|
645 } |
|
646 |
|
647 HbMenu* menu = mRefreshedView->menu(); |
|
648 |
|
649 std::auto_ptr<HbAction> endAction( q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete"))) ); |
|
650 connect(endAction.get(), SIGNAL(triggered()), this, SLOT(deleteList())); |
|
651 menu->addAction(endAction.get()); |
|
652 endAction.release(); |
|
653 |
|
654 QString title; |
|
655 if(mCertView == EPersonalView) |
|
656 { |
|
657 title = "Move to Device"; |
|
658 } |
|
659 else if(mCertView == EDeviceView) |
|
660 { |
|
661 title = "Move to Personal"; |
|
662 } |
|
663 std::auto_ptr<HbAction> moveAction(q_check_ptr(new HbAction(title))); |
|
664 connect(moveAction.get(), SIGNAL(triggered()), this, SLOT(moveCert())); |
|
665 menu->addAction(moveAction.get()); |
|
666 moveAction.release(); |
|
667 |
|
668 std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical))); |
|
669 |
|
670 HbListWidget* mCertificateList = q_check_ptr(new HbListWidget(this)); |
|
671 |
|
672 for(int index = 0; index< count; index++) |
|
673 { |
|
674 QString certificateLabel = certLabel(index); |
|
675 std::auto_ptr<HbListWidgetItem> singleCert(q_check_ptr(new HbListWidgetItem())); |
|
676 singleCert->setText(certificateLabel); |
|
677 mCertificateList->addItem(singleCert.get()); |
|
678 singleCert.release(); |
|
679 } // end of for loop |
|
680 |
|
681 connect(mCertificateList, SIGNAL(activated(QModelIndex)), this, SLOT(openCertFromList(QModelIndex))); |
|
682 connect(mCertificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); |
|
683 |
|
684 layout->addItem(mCertificateList); |
|
685 |
|
686 // Refresh current view |
|
687 QObject::connect(mRefreshedView , SIGNAL(aboutToClose()), this, SLOT(viewDone())); |
|
688 mPrevView = mainWindow()->currentView(); |
|
689 mainWindow()->addView(mRefreshedView); |
|
690 mainWindow()->setCurrentView(mRefreshedView); |
|
691 mRefreshedView->setLayout(layout.get()); |
|
692 layout.release(); |
|
693 } |
|
694 |
|
695 |
|
696 void CpCertView::viewDone() |
|
697 { |
|
698 mCurrentView = mainWindow()->currentView(); |
|
699 mCurrentView->deleteLater(); |
|
700 mCurrentView= NULL; |
|
701 mainWindow()->setCurrentView(mOriginalView); |
|
702 } |
|
703 void CpCertView::showTrustSettings() |
|
704 { |
|
705 mCurrentView = q_check_ptr(new CpCertTrustView(mPos, *mCertDataContainer)); |
|
706 connect(mCurrentView , SIGNAL(aboutToClose()), this, SLOT(saveTrustSettings())); |
|
707 mPrevView = mainWindow()->currentView(); |
|
708 mainWindow()->addView(mCurrentView); |
|
709 mainWindow()->setCurrentView(mCurrentView); |
|
710 } |
|
711 |
|
712 void CpCertView::saveTrustSettings() |
|
713 { |
|
714 ((CpCertTrustView*)mCurrentView)->saveTrustSettings(); |
|
715 displayPreviousView(); |
|
716 } |
|
717 |
|
718 void CpCertView::moveSelectedCert() |
|
719 { |
|
720 RArray<TInt> pos; |
|
721 pos.Append(mPos); |
|
722 moveCertList(pos); |
|
723 } |
|
724 |
|
725 void CpCertView::moveCertList(RArray<TInt>& indexList) |
|
726 { |
|
727 HbMessageBox note(HbMessageBox::MessageTypeQuestion); |
|
728 note.setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_info_move")))); |
|
729 if( mCertView == EPersonalView ) |
|
730 { |
|
731 note.setText(hbTrId("txt_certificate_manager_info_device_certificates_c")); |
|
732 } |
|
733 else if( mCertView == EDeviceView ) |
|
734 { |
|
735 note.setText("Use of Personal certificates may require user confirmation. Proceed?"); |
|
736 } |
|
737 |
|
738 note.setPrimaryAction(q_check_ptr(new HbAction("Yes"))); |
|
739 note.setSecondaryAction(q_check_ptr(new HbAction("No"))); |
|
740 note.setTimeout(HbPopup::NoTimeout); |
|
741 note.setIconVisible (EFalse); |
|
742 HbAction* result = note.exec(); |
|
743 |
|
744 if (result != note.primaryAction()) |
|
745 { |
|
746 return; |
|
747 } |
|
748 |
|
749 TInt count = indexList.Count(); |
|
750 |
|
751 for(TInt index = 0 ; index < count; ++index) |
|
752 { |
|
753 CCTCertInfo* entry = NULL; |
|
754 if(mCertView == EPersonalView) |
|
755 { |
|
756 entry = mCertDataContainer->iUserLabelEntries[ indexList[index] ]->iUserEntry; |
|
757 } |
|
758 else if(mCertView == EDeviceView) |
|
759 { |
|
760 entry = mCertDataContainer->iDeviceLabelEntries[ indexList[index] ]->iDeviceEntry; |
|
761 } |
|
762 |
|
763 // Move key first |
|
764 TCTKeyAttributeFilter keyFilter; |
|
765 keyFilter.iKeyId = entry->SubjectKeyId(); |
|
766 keyFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
|
767 |
|
768 TUid sourceCertStoreUid = TUid::Uid(0); |
|
769 TUid targetCertStoreUid = TUid::Uid(0); |
|
770 TUid sourceKeyStoreUid = TUid::Uid(0); |
|
771 TUid targetKeyStoreUid = TUid::Uid(0); |
|
772 |
|
773 if(mCertView == EPersonalView) |
|
774 { |
|
775 sourceKeyStoreUid = KCMFileKeyStoreTokenUid; |
|
776 targetKeyStoreUid = KCMDeviceKeyStoreTokenUid; |
|
777 sourceCertStoreUid = KCMFileCertStoreTokenUid; |
|
778 targetCertStoreUid = KCMDeviceCertStoreTokenUid; |
|
779 } |
|
780 else if(mCertView == EDeviceView) |
|
781 { |
|
782 sourceKeyStoreUid = KCMDeviceKeyStoreTokenUid; |
|
783 targetKeyStoreUid = KCMFileKeyStoreTokenUid; |
|
784 sourceCertStoreUid = KCMDeviceCertStoreTokenUid; |
|
785 targetCertStoreUid = KCMFileCertStoreTokenUid; |
|
786 } |
|
787 try |
|
788 { |
|
789 |
|
790 QT_TRAP_THROWING( mCertDataContainer->iWrapper->MoveKeyL( |
|
791 mCertDataContainer->KeyManager(), keyFilter, sourceKeyStoreUid, targetKeyStoreUid )); |
|
792 |
|
793 // Move certificate |
|
794 QT_TRAP_THROWING( mCertDataContainer->iWrapper->MoveCertL( |
|
795 mCertDataContainer->CertManager(), *entry, sourceCertStoreUid, targetCertStoreUid ) ); |
|
796 |
|
797 } |
|
798 catch(const std::exception& exception) |
|
799 { |
|
800 QString error(exception.what()); |
|
801 QT_TRAP_THROWING(mCertDataContainer->ShowErrorNoteL( error.toInt() )); |
|
802 User::Exit( KErrNone ); |
|
803 } |
|
804 |
|
805 try |
|
806 { |
|
807 if(mCertView == EPersonalView) |
|
808 { |
|
809 QT_TRAP_THROWING( mCertDataContainer->RefreshUserCertEntriesL() ); |
|
810 } |
|
811 else if(mCertView == EDeviceView) |
|
812 { |
|
813 QT_TRAP_THROWING( mCertDataContainer->RefreshDeviceCertEntriesL() ); |
|
814 } |
|
815 } |
|
816 catch(const std::exception& exception) |
|
817 { |
|
818 QString error(exception.what()); |
|
819 if ( error.toInt() == KErrCorrupt ) |
|
820 { |
|
821 QT_TRAP_THROWING(mCertDataContainer->ShowErrorNoteL( error.toInt()) ); |
|
822 User::Exit( KErrNone ); |
|
823 } |
|
824 // have to call straight away the Exit |
|
825 // showing any error notes would corrupt the display |
|
826 User::Exit( error.toInt() ); |
|
827 } |
|
828 } // for |
|
829 // Refresh current view |
|
830 QT_TRAP_THROWING(refreshView(refreshListL())); |
|
831 } |
|
832 |