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