cpsecplugins/cpadvancedsecplugin/src/cpcertview.cpp
changeset 30 cc1cea6aabaf
parent 26 aad866c37519
child 59 881d92421467
equal deleted inserted replaced
26:aad866c37519 30:cc1cea6aabaf
    40 #include <hblistview.h>
    40 #include <hblistview.h>
    41 #include <QStandardItemModel>
    41 #include <QStandardItemModel>
    42 #include <QModelIndexList>
    42 #include <QModelIndexList>
    43 #include <hbmessagebox.h>
    43 #include <hbmessagebox.h>
    44 #include <memory>
    44 #include <memory>
    45 
    45 #include <../../inc/cpsecplugins.h>
    46 #include "cpcertdetailview.h"
    46 #include "cpcertdetailview.h"
    47 #include "cpcertview.h"
    47 #include "cpcertview.h"
    48 #include "cpcertdatacontainer.h"
    48 #include "cpcertdatacontainer.h"
    49 #include "cpcerttrustview.h"
    49 #include "cpcerttrustview.h"
    50 #include "cpcertmanuisyncwrapper.h"
    50 #include "cpcertmanuisyncwrapper.h"
    59 	  mListView(NULL),
    59 	  mListView(NULL),
    60 	  mSelectAllView(NULL),
    60 	  mSelectAllView(NULL),
    61 	  mOriginalView(NULL),
    61 	  mOriginalView(NULL),
    62 	  mNote(NULL)
    62 	  mNote(NULL)
    63 	{
    63 	{
    64 	
    64 	RDEBUG("0", 0);
    65 	mOriginalView = mainWindow()->currentView();
    65 	mOriginalView = mainWindow()->currentView();
    66 	
    66 	
    67 	HbMenu* menu = this->menu();   
    67 	HbMenu* menu = this->menu();   
    68 	std::auto_ptr<HbAction> deleteAction(new HbAction(hbTrId("txt_common_menu_delete")));
    68 	std::auto_ptr<HbAction> deleteAction(new HbAction(hbTrId("txt_common_menu_delete")));
    69 	connect(deleteAction.get(), SIGNAL(triggered()), this, SLOT(deleteList()));    
    69 	connect(deleteAction.get(), SIGNAL(triggered()), this, SLOT(deleteList()));    
    87 		}
    87 		}
    88 	else if(currentView == EDeviceView)
    88 	else if(currentView == EDeviceView)
    89 		{
    89 		{
    90 		title = "Move to Personal";  
    90 		title = "Move to Personal";  
    91 		}
    91 		}
    92 	std::auto_ptr<HbAction> moveToDeviceAction(q_check_ptr(new HbAction(title)));   
    92 	RDEBUG("0", 0);
    93 	connect(moveToDeviceAction.get(), SIGNAL(triggered()), this, SLOT(moveCert()));    
    93 	if(currentView == EPersonalView || currentView == EDeviceView)
    94 	menu->addAction(moveToDeviceAction.get());
    94 		{
    95 	moveToDeviceAction.release();
    95 		std::auto_ptr<HbAction> moveToDeviceAction(q_check_ptr(new HbAction(title)));   
    96 			
    96 		connect(moveToDeviceAction.get(), SIGNAL(triggered()), this, SLOT(moveCert()));    
       
    97 		menu->addAction(moveToDeviceAction.get());
       
    98 		moveToDeviceAction.release();
       
    99 		}	
       
   100 	
    97 	setDetails(currentView);
   101 	setDetails(currentView);
    98 	TInt count = 0;
   102 	TInt count = 0;
    99 	try
   103 	try
   100 		{
   104 		{
   101 		QT_TRAP_THROWING(mCertDataContainer = CpCertDataContainer::NewL());
   105 		QT_TRAP_THROWING(mCertDataContainer = CpCertDataContainer::NewL());
   104 	catch(const std::exception& exception)
   108 	catch(const std::exception& exception)
   105 		{
   109 		{
   106 		HbMessageBox::information(exception.what());
   110 		HbMessageBox::information(exception.what());
   107 		throw(exception);
   111 		throw(exception);
   108 		}
   112 		}
   109 	
   113 	RDEBUG("0", 0);
   110 	for(int index = 0; index< count; index++)
   114 	for(int index = 0; index< count; index++)
   111 		{
   115 		{
   112 		QString certificateLabel = certLabel(index);
   116 		QString certificateLabel = certLabel(index);
   113 		std::auto_ptr<HbListWidgetItem> singleCert(q_check_ptr(new HbListWidgetItem()));
   117 		std::auto_ptr<HbListWidgetItem> singleCert(q_check_ptr(new HbListWidgetItem()));
   114 		singleCert->setText(certificateLabel);
   118 		singleCert->setText(certificateLabel);
   120 	connect(certificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); 
   124 	connect(certificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); 
   121 	
   125 	
   122 	layout->addItem(certificateList);
   126 	layout->addItem(certificateList);
   123 	setLayout(layout.get());
   127 	setLayout(layout.get());
   124 	layout.release();
   128 	layout.release();
       
   129 	
       
   130 	mPopup = q_check_ptr(new HbDialog());
       
   131 	mContextMenu = q_check_ptr(new HbMenu());
       
   132 	
       
   133 	RDEBUG("0", 0);
   125 	}
   134 	}
   126 
   135 
   127 CpCertView::~CpCertView()
   136 CpCertView::~CpCertView()
   128 	{
   137 	{
   129 	delete mCertDataContainer;
   138 	delete mCertDataContainer;
   130 	mCertDataContainer = NULL;
   139 	mCertDataContainer = NULL;
   131 	
   140 	RDEBUG("0", 0);
   132 	if(mPrevView)
   141 	if(mPrevView)
   133 		{
   142 		{
   134 		mPrevView->deleteLater();
   143 		mPrevView->deleteLater();
   135 		mPrevView= NULL;
   144 		mPrevView= NULL;
   136 		}
   145 		}
   162 	
   171 	
   163 	delete mPopup;
   172 	delete mPopup;
   164 	
   173 	
   165 	delete mNote;
   174 	delete mNote;
   166 	mNote = NULL;
   175 	mNote = NULL;
       
   176 	
       
   177 	delete mContextMenu;
       
   178 	
   167 	}
   179 	}
   168 	
   180 	
   169 void CpCertView::setDetails(CpCertView::TCertificateViews currentView)
   181 void CpCertView::setDetails(CpCertView::TCertificateViews currentView)
   170 	{
   182 	{
       
   183 	RDEBUG("0", 0);
   171 	switch(currentView)
   184 	switch(currentView)
   172 		{
   185 		{
   173 		case EAuthorityView:
   186 		case EAuthorityView:
   174 		setTitle(hbTrId("txt_certificate_manager_list_authority_certificate"));
   187 		setTitle(hbTrId("txt_certificate_manager_list_authority_certificate"));
   175 		mCertView = EAuthorityView;
   188 		mCertView = EAuthorityView;
   192 		}
   205 		}
   193 	}
   206 	}
   194 
   207 
   195 void CpCertView::indicateLongPress(HbAbstractViewItem *item,QPointF coords)
   208 void CpCertView::indicateLongPress(HbAbstractViewItem *item,QPointF coords)
   196 	{
   209 	{
   197 	std::auto_ptr<HbMenu> contextMenu(q_check_ptr(new HbMenu()));
   210 	RDEBUG("0", 0);
   198 	mPos = item->modelIndex().row();   // Pos will tell you what is the certificate clicked in particular view.
   211 	mPos = item->modelIndex().row();   // Pos will tell you what is the certificate clicked in particular view.
   199 	
   212 	
   200 	std::auto_ptr<HbAction> open(q_check_ptr(new HbAction(hbTrId("txt_common_menu_open"))));     
   213 	mContextMenu->clearActions();
   201 	connect(open.get(), SIGNAL(triggered()), this, SLOT( openCertificate()));    
   214 	std::auto_ptr<HbAction> open(q_check_ptr(new HbAction(hbTrId("txt_common_menu_open"))));
   202 	contextMenu->addAction(open.get());			
   215 	connect(open.get(), SIGNAL(triggered()), this, SLOT( openCertificate()));
       
   216 	mContextMenu->addAction(open.get());			
   203 	open.release();
   217 	open.release();
   204 	
   218 	
   205 	QString moveTitle;
   219 	QString moveTitle;
   206 	
   220 	
   207 	if(mCertView == EAuthorityView)
   221 	if(mCertView == EAuthorityView)
   208 		{
   222 		{
   209 		std::auto_ptr<HbAction> trustSettings(q_check_ptr(new HbAction(hbTrId("txt_certificate_manager_menu_trust_settings")))); 
   223 		std::auto_ptr<HbAction> trustSettings(q_check_ptr(new HbAction(hbTrId("txt_certificate_manager_menu_trust_settings")))); 
   210 		connect(trustSettings.get(), SIGNAL(triggered()), this, SLOT(showTrustSettings()));    
   224 		connect(trustSettings.get(), SIGNAL(triggered()), this, SLOT(showTrustSettings()));    
   211 		contextMenu->addAction(trustSettings.get());
   225 		mContextMenu->addAction(trustSettings.get());
   212 		trustSettings.release();
   226 		trustSettings.release();
   213 		}
   227 		}
   214 	else if(mCertView == EPersonalView)
   228 	else if(mCertView == EPersonalView)
   215 		{
   229 		{
   216 		moveTitle = hbTrId("txt_certificate_manager_menu_move_to_device_certif");
   230 		moveTitle = hbTrId("txt_certificate_manager_menu_move_to_device_certif");
   217 		}
   231 		}
   218 	else if(mCertView == EDeviceView)
   232 	else if(mCertView == EDeviceView)
   219 		{
   233 		{
   220 		moveTitle = hbTrId("txt_certificate_manager_menu_move_to_personal_cert");
   234 		moveTitle = hbTrId("txt_certificate_manager_menu_move_to_personal_cert");
   221 		}	
   235 		}	
   222 	std::auto_ptr<HbAction> moveCert(q_check_ptr(new HbAction(moveTitle)));     
   236 	
   223 	connect(moveCert.get(), SIGNAL(triggered()), this, SLOT(moveSelectedCert()));    
   237 	if(mCertView == EPersonalView || mCertView == EDeviceView )
   224 	contextMenu->addAction(moveCert.get());
   238 		{
   225 	moveCert.release();
   239 		std::auto_ptr<HbAction> moveCert(q_check_ptr(new HbAction(moveTitle)));     
   226 			
   240 		connect(moveCert.get(), SIGNAL(triggered()), this, SLOT(moveSelectedCert()));    
       
   241 		mContextMenu->addAction(moveCert.get());
       
   242 		moveCert.release();
       
   243 		}
       
   244 	
       
   245 	RDEBUG("0", 0);
   227 	if( certAt(mPos)->IsDeletable() )
   246 	if( certAt(mPos)->IsDeletable() )
   228 		{
   247 		{
   229 		std::auto_ptr<HbAction> menuDelete(q_check_ptr(new HbAction(hbTrId("txt_common_menu_delete")))); 
   248 		std::auto_ptr<HbAction> menuDelete(q_check_ptr(new HbAction(hbTrId("txt_common_menu_delete")))); 
   230 		connect(menuDelete.get(), SIGNAL(triggered()), this, SLOT(deleteCertificate()));    
   249 		connect(menuDelete.get(), SIGNAL(triggered()), this, SLOT(deleteCertificate()));    
   231 		contextMenu->addAction(menuDelete.get());
   250 		mContextMenu->addAction(menuDelete.get());
   232 		menuDelete.release();
   251 		menuDelete.release();
   233 		}
   252 		}
   234 	contextMenu->open();
   253 	mContextMenu->setPreferredPos(coords);
   235 	contextMenu->setPreferredPos(coords);
   254 	mContextMenu->open();
   236 	}
   255 	}
   237 
   256 
   238 void CpCertView::openCertFromList(const QModelIndex& modelIndex)
   257 void CpCertView::openCertFromList(const QModelIndex& modelIndex)
   239 	{	
   258 	{	
       
   259 	RDEBUG("0", 0);
   240 	// Pos will tell you what is the certificate clicked in particular view.
   260 	// Pos will tell you what is the certificate clicked in particular view.
   241 	mPos = modelIndex.row();   
   261 	mPos = modelIndex.row();   
   242 	openCertificate();
   262 	openCertificate();
   243 	}
   263 	}
   244 
   264 
   245 void CpCertView::openCertificate()
   265 void CpCertView::openCertificate()
   246 	{	
   266 	{
       
   267 	RDEBUG("0", 0);
   247 	mCurrentView = q_check_ptr(new CpCertDetailView(mCertView,mPos,*mCertDataContainer));    
   268 	mCurrentView = q_check_ptr(new CpCertDetailView(mCertView,mPos,*mCertDataContainer));    
   248 	connect(mCurrentView, SIGNAL(aboutToClose()), this, SLOT(displayPreviousView()));
   269 	connect(mCurrentView, SIGNAL(aboutToClose()), this, SLOT(displayPreviousView()));
   249 	mPrevView = mainWindow()->currentView();   
   270 	mPrevView = mainWindow()->currentView();   
   250 	mainWindow()->addView(mCurrentView);
   271 	mainWindow()->addView(mCurrentView);
   251 	mainWindow()->setCurrentView(mCurrentView);  		
   272 	mainWindow()->setCurrentView(mCurrentView);  		
   252 	}
   273 	}
   253 	
   274 	
   254 void CpCertView::displayPreviousView()  
   275 void CpCertView::displayPreviousView()  
   255 	{
   276 	{
       
   277 	RDEBUG("0", 0);
   256 	mainWindow()->removeView(mCurrentView);    
   278 	mainWindow()->removeView(mCurrentView);    
   257 	mCurrentView->deleteLater();
   279 	mCurrentView->deleteLater();
   258 	mCurrentView= NULL;
   280 	mCurrentView= NULL;
   259 	mainWindow()->setCurrentView(mPrevView);  	
   281 	mainWindow()->setCurrentView(mPrevView);  	
   260 	}
   282 	}
   261 	
   283 	
   262 void CpCertView::deleteCertificate()
   284 void CpCertView::deleteCertificate()
   263 	{
   285 	{
       
   286 	RDEBUG("0", 0);
   264 	RArray<TInt> pos;
   287 	RArray<TInt> pos;
   265 	pos.Append(mPos);
   288 	pos.Append(mPos);
   266 	QT_TRAP_THROWING(deleteCerts(pos));
   289 	QT_TRAP_THROWING(deleteCertsL(pos));
   267 	}		
   290 	}		
   268 	
   291 	
   269 void CpCertView::deleteList()
   292 void CpCertView::deleteList()
   270 	{
   293 	{
       
   294 	RDEBUG("0", 0);
   271 	mSelectAll = EFalse;
   295 	mSelectAll = EFalse;
   272 	mPopup = new HbDialog();
       
   273 
       
   274 	mPopup->setDismissPolicy(HbDialog::NoDismiss);
   296 	mPopup->setDismissPolicy(HbDialog::NoDismiss);
   275 	// Set the label as heading widget
   297 	// Set the label as heading widget
   276 	mPopup->setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_setlabel_certificates"))));
   298 	mPopup->setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_setlabel_certificates"))));
   277 	
   299 	
   278 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
   300 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
   296 	
   318 	
   297 	// Create a model
   319 	// Create a model
   298 	QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this));
   320 	QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this));
   299 	TInt count=0;
   321 	TInt count=0;
   300 	QT_TRAP_THROWING( count = refreshListL());
   322 	QT_TRAP_THROWING( count = refreshListL());
   301 	
   323 	RDEBUG("0", 0);
   302 	for(TInt index = 0; index < count ; ++index)
   324 	for(TInt index = 0; index < count ; ++index)
   303 		{
   325 		{
   304 		const CCTCertInfo* cert = certAt(index);
   326 		const CCTCertInfo* cert = certAt(index);
   305 		if( cert->IsDeletable() )
   327 		if( cert->IsDeletable() )
   306 			{
   328 			{
   325 	widget.release();
   347 	widget.release();
   326 	
   348 	
   327 	mPopup->setPrimaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete"))));
   349 	mPopup->setPrimaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete"))));
   328 	mPopup->setSecondaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_button_cancel"))));
   350 	mPopup->setSecondaryAction(q_check_ptr(new HbAction(hbTrId("txt_common_button_cancel"))));
   329 	mPopup->setTimeout(HbPopup::NoTimeout);
   351 	mPopup->setTimeout(HbPopup::NoTimeout);
   330 	
   352 	RDEBUG("0", 0);
   331 	// Launch popup syncronously
   353 	// Launch popup syncronously
   332 	mPopup->open(this, SLOT(handleMultipleDelete(HbAction*)));
   354 	mPopup->open(this, SLOT(handleMultipleDelete(HbAction*)));
   333 
   355 
   334 }
   356 }
   335 
   357 
   336 void CpCertView::handleMultipleDelete(HbAction* action)
   358 void CpCertView::handleMultipleDelete(HbAction* action)
   337 {
   359 {
       
   360 	RDEBUG("0", 0);
   338 	if(action == mPopup->primaryAction())
   361 	if(action == mPopup->primaryAction())
   339 		{
   362 		{
   340 		QItemSelectionModel *selectionModel = mListView->selectionModel();
   363 		QItemSelectionModel *selectionModel = mListView->selectionModel();
   341 		QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes();
   364 		QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes();
   342 		TInt deleteCount = mWidgetItemsToRemove.count();
   365 		TInt deleteCount = mWidgetItemsToRemove.count();
   343 		// start deleting from end of array so that the indexes do not changes of the ones
   366 		// start deleting from end of array so that the indexes do not changes of the ones
   344 		// at the front.
   367 		// at the front.
   345 		RArray<TInt> actualIndex;
   368 		RArray<TInt> actualIndex;
   346 		QT_TRAP_THROWING(CleanupClosePushL(actualIndex));
   369 		QT_TRAP_THROWING
   347 		for (TInt index = deleteCount-1; index>= 0 ; --index) 
   370 			(
   348 			{
   371 			CleanupClosePushL(actualIndex);
   349 			TInt selectedItemIndex = mWidgetItemsToRemove[index].row();
   372 			for (TInt index = deleteCount-1; index>= 0 ; --index) 
   350 			actualIndex.Append( mSelectionIndex[selectedItemIndex] );
   373 				{
   351 			}
   374 				TInt selectedItemIndex = mWidgetItemsToRemove[index].row();
   352 		deleteCerts(actualIndex);
   375 				actualIndex.Append( mSelectionIndex[selectedItemIndex] );
   353 		 CleanupStack::PopAndDestroy(&actualIndex);
   376 				}
   354 		}
   377 			deleteCertsL(actualIndex);
       
   378 			CleanupStack::PopAndDestroy(&actualIndex);
       
   379 			) // QT_TRAP_THROWING
       
   380 		}
       
   381 	RDEBUG("0", 0);
   355 	mListView->deleteLater();
   382 	mListView->deleteLater();
   356 	mListView = NULL;
   383 	mListView = NULL;
   357 	mSelectAllView->deleteLater();
   384 	mSelectAllView->deleteLater();
   358 	mSelectAllView = NULL; 
   385 	mSelectAllView = NULL; 
   359 	delete mPopup;
       
   360 	mPopup = NULL;
       
   361 	}
   386 	}
   362 
   387 
   363 void CpCertView::moveCert()
   388 void CpCertView::moveCert()
   364 	{
   389 	{
       
   390 	RDEBUG("0", 0);
   365 	mSelectAll = EFalse;
   391 	mSelectAll = EFalse;
   366 	mPopup = new HbDialog();
       
   367 	mPopup->setDismissPolicy(HbDialog::NoDismiss);
   392 	mPopup->setDismissPolicy(HbDialog::NoDismiss);
   368 	// Set the label as heading widget
   393 	// Set the label as heading widget
   369 	if(mCertView == EPersonalView)
   394 	if(mCertView == EPersonalView)
   370 		{
   395 		{
   371 		mPopup->setHeadingWidget(q_check_ptr(new HbLabel(tr("Move To Device"))));
   396 		mPopup->setHeadingWidget(q_check_ptr(new HbLabel(tr("Move To Device"))));
   394 	connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
   419 	connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
   395 	
   420 	
   396 	// Create a model
   421 	// Create a model
   397 	QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this));
   422 	QStandardItemModel* model = q_check_ptr(new QStandardItemModel(this));
   398 	TInt count =0;
   423 	TInt count =0;
       
   424 	RDEBUG("0", 0);
   399 	QT_TRAP_THROWING(count = refreshListL());
   425 	QT_TRAP_THROWING(count = refreshListL());
   400 	for(TInt index = 0; index < count ; ++index)
   426 	for(TInt index = 0; index < count ; ++index)
   401 		{
   427 		{
   402 		// Populate the model with content
   428 		// Populate the model with content
   403 		std::auto_ptr<QStandardItem> certItem(q_check_ptr(new QStandardItem()));
   429 		std::auto_ptr<QStandardItem> certItem(q_check_ptr(new QStandardItem()));
   416 	std::auto_ptr<HbWidget> widget(q_check_ptr(new HbWidget()));
   442 	std::auto_ptr<HbWidget> widget(q_check_ptr(new HbWidget()));
   417 	widget->setLayout(layout.get());	
   443 	widget->setLayout(layout.get());	
   418 	layout.release();
   444 	layout.release();
   419 	mPopup->setContentWidget(widget.get());
   445 	mPopup->setContentWidget(widget.get());
   420 	widget.release();
   446 	widget.release();
   421 	
   447 	RDEBUG("0", 0);
   422 	mPopup->setPrimaryAction(q_check_ptr(new HbAction(tr("Yes"))));
   448 	mPopup->setPrimaryAction(q_check_ptr(new HbAction(tr("Yes"))));
   423 	mPopup->setSecondaryAction(q_check_ptr(new HbAction(tr("No"))));
   449 	mPopup->setSecondaryAction(q_check_ptr(new HbAction(tr("No"))));
   424 	mPopup->setTimeout(HbPopup::NoTimeout);
   450 	mPopup->setTimeout(HbPopup::NoTimeout);
   425 	
   451 	
   426 	// Launch popup syncronously
   452 	// Launch popup syncronously
   427 	 mPopup->open(this, SLOT(handleMoveCertDialog(HbAction*)));
   453 	 mPopup->open(this, SLOT(handleMoveCertDialog(HbAction*)));
       
   454 	 RDEBUG("0", 0);
   428 }
   455 }
   429 
   456 
   430 void CpCertView::handleMoveCertDialog(HbAction* action)
   457 void CpCertView::handleMoveCertDialog(HbAction* action)
   431 {	
   458 {	
       
   459 	RDEBUG("0", 0);
   432 	if(action == mPopup->primaryAction())
   460 	if(action == mPopup->primaryAction())
   433 		{
   461 		{
   434 		QItemSelectionModel *selectionModel = mListView->selectionModel();
   462 		QItemSelectionModel *selectionModel = mListView->selectionModel();
   435 		QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes();
   463 		QModelIndexList mWidgetItemsToRemove = selectionModel->selectedIndexes();
   436 		TInt deleteCount = mWidgetItemsToRemove.count();
   464 		TInt deleteCount = mWidgetItemsToRemove.count();
   437 		// start deleting from end of array so that the indexes do not changes of the ones
   465 		// start deleting from end of array so that the indexes do not changes of the ones
   438 		// at the front.
   466 		// at the front.
   439 		RArray<TInt> actualIndex;
   467 		RArray<TInt> actualIndex;
   440 		QT_TRAP_THROWING(CleanupClosePushL(actualIndex));
   468 		RDEBUG("0", 0);
   441 		 for (TInt index = deleteCount-1; index>= 0 ; --index) 
   469 		QT_TRAP_THROWING
   442 			 {
   470 			(
   443 			 TInt selectedItemIndex = mWidgetItemsToRemove[index].row();
   471 			CleanupClosePushL(actualIndex);
   444 			 actualIndex.Append(mSelectionIndex[selectedItemIndex]);	 
   472 			 for (TInt index = deleteCount-1; index>= 0 ; --index) 
   445 			 }
   473 				 {
   446 		 moveCertList(actualIndex);
   474 				 TInt selectedItemIndex = mWidgetItemsToRemove[index].row();
   447 		 CleanupStack::PopAndDestroy(&actualIndex); 
   475 				 actualIndex.Append(mSelectionIndex[selectedItemIndex]);	 
       
   476 				 }
       
   477 			 moveCertList(actualIndex);
       
   478 			 CleanupStack::PopAndDestroy(&actualIndex);
       
   479 			 )
   448 		}
   480 		}
   449 	mListView->deleteLater();
   481 	mListView->deleteLater();
   450 	mListView = NULL;	
   482 	mListView = NULL;	
   451 	mSelectAllView->deleteLater();
   483 	mSelectAllView->deleteLater();
   452 	mSelectAllView = NULL;
   484 	mSelectAllView = NULL;
   453 	delete mPopup;
   485 	RDEBUG("0", 0);
   454 	mPopup = NULL;
       
   455 	}
   486 	}
   456 
   487 
   457 void CpCertView::selectAll()
   488 void CpCertView::selectAll()
   458 	{
   489 	{
       
   490 	RDEBUG("0", 0);
   459 	if(mSelectAll == EFalse)
   491 	if(mSelectAll == EFalse)
   460 		{
   492 		{
   461 		mListView->selectAll();
   493 		mListView->selectAll();
   462 		mSelectAll= ETrue;
   494 		mSelectAll= ETrue;
   463 		}
   495 		}
   466 		mListView->clearSelection();
   498 		mListView->clearSelection();
   467 		mSelectAll= EFalse;
   499 		mSelectAll= EFalse;
   468 		}
   500 		}
   469 	}
   501 	}
   470 
   502 
   471 void CpCertView::deleteCerts( RArray<TInt>& indexList )
   503 void CpCertView::deleteCertsL( RArray<TInt>& indexList )
   472     {
   504     {
   473   	mIndexList = indexList;
   505     RDEBUG("0", 0);
   474 	TInt count = indexList.Count();
   506     TInt count = indexList.Count();
   475 	    
   507     for(int index = 0;index <count;++index )
   476 	mNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   508     	{
       
   509 		mIndexList.Append(indexList[index]);
       
   510     	}
       
   511     
       
   512   	mNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   477 	QString deleteMsg;
   513 	QString deleteMsg;
   478 	QString sCount;
   514 	QString sCount;
   479 	if(count == 1)
   515 	if(count == 1)
   480 		{
   516 		{
   481 		deleteMsg = "Delete %1?";
   517 		deleteMsg = "Delete %1?";
   485 	else
   521 	else
   486 		{
   522 		{
   487 		deleteMsg = "Delete %1 items?";
   523 		deleteMsg = "Delete %1 items?";
   488 		sCount.setNum(count);
   524 		sCount.setNum(count);
   489 		}
   525 		}
   490 	
   526 	RDEBUG("0", 0);
   491 	deleteMsg = deleteMsg.arg(sCount);
   527 	deleteMsg = deleteMsg.arg(sCount);
   492 	mNote->setText(deleteMsg);
   528 	mNote->setText(deleteMsg);
   493 	mNote->setPrimaryAction(q_check_ptr(new HbAction("Yes")));
       
   494 	mNote->setSecondaryAction(q_check_ptr(new HbAction("No")));
       
   495 	mNote->setTimeout(HbPopup::NoTimeout);
   529 	mNote->setTimeout(HbPopup::NoTimeout);
   496 	mNote->open(this,SLOT(handleDeleteDialog(HbAction*)));
   530 	mNote->open(this,SLOT(handleDeleteDialog(HbAction*)));
   497 
   531 
   498 }
   532 }
   499 
   533 
   500 void CpCertView::handleDeleteDialog(HbAction* action)
   534 void CpCertView::handleDeleteDialog(HbAction* action)
   501 {
   535 {
   502 	
   536 	RDEBUG("0", 0);
   503 	TInt count = mIndexList.Count();
   537 	TInt count = mIndexList.Count();
   504 	
   538 	
   505 	if (action != mNote->primaryAction() || count == 0 )
   539 	if (action != mNote->primaryAction() || count == 0 )
   506 		{
   540 		{
   507 		return;
   541 		return;
   508 		}
   542 		}
   509 		
   543 		
   510     RPointerArray<CCTCertInfo> errCerts;
   544     RPointerArray<CCTCertInfo> errCerts;
   511     QT_TRAP_THROWING(CleanupClosePushL(errCerts));
   545     QT_TRAP_THROWING(
       
   546     		CleanupClosePushL(errCerts);
   512     
   547     
   513     for(TInt index = 0; index < count; ++index)
   548 		for(TInt index = 0; index < count; ++index)
   514     	{
   549 			{
   515 		const CCTCertInfo* entry = certAt(mIndexList[index]);
   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);
   516 		
   584 		
   517 		if( mCertView == EPersonalView || mCertView == EAuthorityView )
   585 		CleanupStack::PopAndDestroy(&errCerts);
   518 			{
   586 		) // QT_TRAP_THROWING
   519 			QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL( 
       
   520 						mCertDataContainer->CertManager(), *entry ));
       
   521 			}
       
   522 		else if( mCertView == ETrustedView )
       
   523 			{
       
   524 			QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL( 
       
   525 						mCertDataContainer->CertManager(),*entry, KCMTrustedServerTokenUid ));
       
   526 			}
       
   527 		else if( mCertView == EDeviceView )
       
   528 			{
       
   529 			QT_TRAP_THROWING( mCertDataContainer->iWrapper->DeleteCertL(
       
   530 						mCertDataContainer->CertManager(), *entry, KCMDeviceCertStoreTokenUid ));
       
   531 			}	
       
   532 		QT_TRAP_THROWING( errCerts.AppendL(entry));
       
   533     	}
       
   534     
   587     
   535     if(errCerts.Count() > 0)
       
   536     	{
       
   537 		QString message("Unable to delete the following certificate: \n");
       
   538 		TInt count = errCerts.Count();
       
   539 		for(TInt index=0;index<count;++index)
       
   540 			{
       
   541 			const TDesC& certLabel = errCerts[index]->Label();
       
   542 			QString certName = QString((QChar*)certLabel.Ptr(),certLabel.Length());
       
   543 			message.append(certName).append("\n");
       
   544 			}
       
   545 		HbMessageBox::warning(message);
       
   546     	}
       
   547     QT_TRAP_THROWING( count = refreshListL());
       
   548 	refreshView(count);
       
   549 	
       
   550 	CleanupStack::PopAndDestroy(&errCerts);
       
   551 	delete mNote;
   588 	delete mNote;
   552 	mNote = NULL;
   589 	mNote = NULL;
   553 	
   590 	RDEBUG("0", 0);
   554     }
   591     }
   555 
   592 
   556 const CCTCertInfo* CpCertView::certAt(TInt index) const
   593 const CCTCertInfo* CpCertView::certAt(TInt index) const
   557 	{
   594 	{
       
   595 	RDEBUG("0", 0);
   558 	CCTCertInfo* currentCert = NULL;
   596 	CCTCertInfo* currentCert = NULL;
   559 	switch(mCertView)
   597 	switch(mCertView)
   560 		{
   598 		{
   561 		case EAuthorityView:
   599 		case EAuthorityView:
   562 			{
   600 			{
   582 	return currentCert;
   620 	return currentCert;
   583 	}
   621 	}
   584 
   622 
   585 QString CpCertView::certLabel(TInt index) const
   623 QString CpCertView::certLabel(TInt index) const
   586 	{
   624 	{
       
   625 	RDEBUG("0", 0);
   587 	CpCertManUICertData* certData = NULL;
   626 	CpCertManUICertData* certData = NULL;
   588 	HBufC* label = NULL;
   627 	HBufC* label = NULL;
   589 	TInt length = 0;
   628 	TInt length = 0;
   590 	switch(mCertView)
   629 	switch(mCertView)
   591 		{
   630 		{
   621 	return QString((QChar*)label->Des().Ptr(), length);
   660 	return QString((QChar*)label->Des().Ptr(), length);
   622 	}
   661 	}
   623 
   662 
   624 TInt CpCertView::refreshListL()
   663 TInt CpCertView::refreshListL()
   625 	{
   664 	{
       
   665 	RDEBUG("0", 0);
   626 	TInt count = 0;
   666 	TInt count = 0;
   627 	switch(mCertView)
   667 	switch(mCertView)
   628 		{
   668 		{
   629 		case EAuthorityView:
   669 		case EAuthorityView:
   630 			mCertDataContainer->RefreshCAEntriesL();
   670 			mCertDataContainer->RefreshCAEntriesL();
   647 	}
   687 	}
   648 
   688 
   649 
   689 
   650 void CpCertView::refreshView( TInt count )
   690 void CpCertView::refreshView( TInt count )
   651 	{
   691 	{
       
   692 	RDEBUG("0", 0);
   652 	if(mRefreshedView)
   693 	if(mRefreshedView)
   653 		{
   694 		{
   654 		mRefreshedView->deleteLater();
   695 		mRefreshedView->deleteLater();
   655 		mRefreshedView = NULL;
   696 		mRefreshedView = NULL;
   656 		}
   697 		}
   679 			break;
   720 			break;
   680 			}
   721 			}
   681 		}	
   722 		}	
   682 	
   723 	
   683 	HbMenu* menu = mRefreshedView->menu();   
   724 	HbMenu* menu = mRefreshedView->menu();   
   684 		
   725 	RDEBUG("0", 0);
   685 	std::auto_ptr<HbAction> endAction( q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete"))) );
   726 	std::auto_ptr<HbAction> endAction( q_check_ptr(new HbAction(hbTrId("txt_common_opt_delete"))) );
   686 	connect(endAction.get(), SIGNAL(triggered()), this, SLOT(deleteList()));    
   727 	connect(endAction.get(), SIGNAL(triggered()), this, SLOT(deleteList()));    
   687 	menu->addAction(endAction.get());
   728 	menu->addAction(endAction.get());
   688 	endAction.release();
   729 	endAction.release();
   689 	
   730 	
   698 		}
   739 		}
   699 	std::auto_ptr<HbAction> moveAction(q_check_ptr(new HbAction(title)));
   740 	std::auto_ptr<HbAction> moveAction(q_check_ptr(new HbAction(title)));
   700 	connect(moveAction.get(), SIGNAL(triggered()), this, SLOT(moveCert()));    
   741 	connect(moveAction.get(), SIGNAL(triggered()), this, SLOT(moveCert()));    
   701 	menu->addAction(moveAction.get());
   742 	menu->addAction(moveAction.get());
   702 	moveAction.release();
   743 	moveAction.release();
   703 			
   744 	RDEBUG("0", 0);
   704 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
   745 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
   705 			
   746 			
   706 	HbListWidget* mCertificateList = q_check_ptr(new HbListWidget(this)); 
   747 	HbListWidget* mCertificateList = q_check_ptr(new HbListWidget(this)); 
   707 
   748 
   708 	for(int index = 0; index< count; index++)
   749 	for(int index = 0; index< count; index++)
   716 	
   757 	
   717 	connect(mCertificateList, SIGNAL(activated(QModelIndex)), this, SLOT(openCertFromList(QModelIndex)));   
   758 	connect(mCertificateList, SIGNAL(activated(QModelIndex)), this, SLOT(openCertFromList(QModelIndex)));   
   718 	connect(mCertificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); 
   759 	connect(mCertificateList, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF))); 
   719 	
   760 	
   720 	layout->addItem(mCertificateList);
   761 	layout->addItem(mCertificateList);
   721 	
   762 	RDEBUG("0", 0);
   722 	// Refresh current view
   763 	// Refresh current view
   723 	QObject::connect(mRefreshedView , SIGNAL(aboutToClose()), this, SLOT(viewDone()));
   764 	QObject::connect(mRefreshedView , SIGNAL(aboutToClose()), this, SLOT(viewDone()));
   724 	mPrevView = mainWindow()->currentView();   
   765 	mPrevView = mainWindow()->currentView();   
   725 	mainWindow()->addView(mRefreshedView);
   766 	mainWindow()->addView(mRefreshedView);
   726 	mainWindow()->setCurrentView(mRefreshedView); 
   767 	mainWindow()->setCurrentView(mRefreshedView); 
   727 	mRefreshedView->setLayout(layout.get());
   768 	mRefreshedView->setLayout(layout.get());
   728 	layout.release();
   769 	layout.release();
       
   770 	RDEBUG("0", 0);
   729 	}
   771 	}
   730 
   772 
   731 
   773 
   732 void CpCertView::viewDone()  
   774 void CpCertView::viewDone()  
   733 	{
   775 	{
       
   776 	RDEBUG("0", 0);
   734 	mCurrentView = mainWindow()->currentView();
   777 	mCurrentView = mainWindow()->currentView();
   735 	mCurrentView->deleteLater();
   778 	mCurrentView->deleteLater();
   736 	mCurrentView= NULL;
   779 	mCurrentView= NULL;
   737 	mainWindow()->setCurrentView(mOriginalView);  	
   780 	mainWindow()->setCurrentView(mOriginalView);  	
   738 	}
   781 	}
   739 void CpCertView::showTrustSettings()
   782 void CpCertView::showTrustSettings()
   740 	{
   783 	{
       
   784 	RDEBUG("0", 0);
   741 	mCurrentView = q_check_ptr(new CpCertTrustView(mPos, *mCertDataContainer));    
   785 	mCurrentView = q_check_ptr(new CpCertTrustView(mPos, *mCertDataContainer));    
   742 	connect(mCurrentView , SIGNAL(aboutToClose()), this, SLOT(saveTrustSettings()));
   786 	connect(mCurrentView , SIGNAL(aboutToClose()), this, SLOT(saveTrustSettings()));
   743 	mPrevView = mainWindow()->currentView();   
   787 	mPrevView = mainWindow()->currentView();   
   744 	mainWindow()->addView(mCurrentView);
   788 	mainWindow()->addView(mCurrentView);
   745 	mainWindow()->setCurrentView(mCurrentView); 
   789 	mainWindow()->setCurrentView(mCurrentView); 
   751 	displayPreviousView();
   795 	displayPreviousView();
   752 	}
   796 	}
   753 
   797 
   754 void CpCertView::moveSelectedCert()
   798 void CpCertView::moveSelectedCert()
   755 	{
   799 	{
       
   800 	RDEBUG("0", 0);
   756 	RArray<TInt> pos;
   801 	RArray<TInt> pos;
   757 	pos.Append(mPos);
   802 	pos.Append(mPos);
   758 	moveCertList(pos);
   803 	moveCertList(pos);
   759 	}
   804 	}
   760 
   805 
   761 void CpCertView::moveCertList(RArray<TInt>& indexList)
   806 void CpCertView::moveCertList(RArray<TInt>& indexList)
   762 	{
   807 	{
   763 		
   808 	RDEBUG("0", 0);
   764 	mIndexList = indexList;
   809 	mIndexList = indexList;
   765 	mNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   810 	mNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   766 	mNote->setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_info_move"))));
   811 	mNote->setHeadingWidget(q_check_ptr(new HbLabel(hbTrId("txt_certificate_manager_info_move"))));
   767 	if( mCertView == EPersonalView )
   812 	if( mCertView == EPersonalView )
   768 		{
   813 		{
   771 	else if( mCertView == EDeviceView )
   816 	else if( mCertView == EDeviceView )
   772 		{
   817 		{
   773 		mNote->setText("Use of Personal certificates may require user confirmation. Proceed?");
   818 		mNote->setText("Use of Personal certificates may require user confirmation. Proceed?");
   774 		}
   819 		}
   775 	
   820 	
   776 	mNote->setPrimaryAction(q_check_ptr(new HbAction("Yes")));
       
   777 	mNote->setSecondaryAction(q_check_ptr(new HbAction("No")));
       
   778 	mNote->setTimeout(HbPopup::NoTimeout);
   821 	mNote->setTimeout(HbPopup::NoTimeout);
   779 	mNote->setIconVisible (EFalse);
   822 	mNote->setIconVisible (EFalse);
   780 	mNote->open(this,SLOT(handleMoveDialog(HbAction*)));
   823 	mNote->open(this,SLOT(handleMoveDialog(HbAction*)));
       
   824 	RDEBUG("0", 0);
   781 }
   825 }
   782 
   826 
   783 void CpCertView::handleMoveDialog(HbAction* action)
   827 void CpCertView::handleMoveDialog(HbAction* action)
   784 {
   828 {
   785 
   829 	RDEBUG("0", 0);
   786 	if (action != mNote->primaryAction())
   830 	if (action != mNote->primaryAction())
   787 	    {
   831 	    {
   788 		return;
   832 		return;
   789 	    }
   833 	    }
   790 	
   834 	
   804 			
   848 			
   805 		// Move key first
   849 		// Move key first
   806 		TCTKeyAttributeFilter keyFilter;
   850 		TCTKeyAttributeFilter keyFilter;
   807 		keyFilter.iKeyId = entry->SubjectKeyId();
   851 		keyFilter.iKeyId = entry->SubjectKeyId();
   808 		keyFilter.iPolicyFilter =  TCTKeyAttributeFilter::EAllKeys;
   852 		keyFilter.iPolicyFilter =  TCTKeyAttributeFilter::EAllKeys;
   809 	
   853 		RDEBUG("0", 0);
   810 		TUid sourceCertStoreUid = TUid::Uid(0);
   854 		TUid sourceCertStoreUid = TUid::Uid(0);
   811 		TUid targetCertStoreUid = TUid::Uid(0);
   855 		TUid targetCertStoreUid = TUid::Uid(0);
   812 		TUid sourceKeyStoreUid = TUid::Uid(0);
   856 		TUid sourceKeyStoreUid = TUid::Uid(0);
   813 		TUid targetKeyStoreUid = TUid::Uid(0);
   857 		TUid targetKeyStoreUid = TUid::Uid(0);
   814 				
   858 				
   824 			sourceKeyStoreUid = KCMDeviceKeyStoreTokenUid;
   868 			sourceKeyStoreUid = KCMDeviceKeyStoreTokenUid;
   825 			targetKeyStoreUid = KCMFileKeyStoreTokenUid;
   869 			targetKeyStoreUid = KCMFileKeyStoreTokenUid;
   826 			sourceCertStoreUid = KCMDeviceCertStoreTokenUid;
   870 			sourceCertStoreUid = KCMDeviceCertStoreTokenUid;
   827 			targetCertStoreUid = KCMFileCertStoreTokenUid;
   871 			targetCertStoreUid = KCMFileCertStoreTokenUid;
   828 			}
   872 			}
       
   873 		RDEBUG("0", 0);
   829 		try
   874 		try
   830 			{
   875 			{
   831 			
   876 			
   832 			QT_TRAP_THROWING( mCertDataContainer->iWrapper->MoveKeyL( 
   877 			QT_TRAP_THROWING( mCertDataContainer->iWrapper->MoveKeyL( 
   833 					mCertDataContainer->KeyManager(), keyFilter, sourceKeyStoreUid, targetKeyStoreUid ));
   878 					mCertDataContainer->KeyManager(), keyFilter, sourceKeyStoreUid, targetKeyStoreUid ));
   841 			{
   886 			{
   842 			QString error(exception.what());
   887 			QString error(exception.what());
   843 			QT_TRAP_THROWING(mCertDataContainer->ShowErrorNoteL( error.toInt() ));
   888 			QT_TRAP_THROWING(mCertDataContainer->ShowErrorNoteL( error.toInt() ));
   844 			User::Exit( KErrNone );
   889 			User::Exit( KErrNone );
   845 			}
   890 			}
   846 		
   891 		RDEBUG("0", 0);
   847 		try
   892 		try
   848 			{
   893 			{
   849 			if(mCertView == EPersonalView)
   894 			if(mCertView == EPersonalView)
   850 				{
   895 				{
   851 				QT_TRAP_THROWING( mCertDataContainer->RefreshUserCertEntriesL() );
   896 				QT_TRAP_THROWING( mCertDataContainer->RefreshUserCertEntriesL() );
   870 		} // for
   915 		} // for
   871 	// Refresh current view
   916 	// Refresh current view
   872 	QT_TRAP_THROWING(refreshView(refreshListL()));	
   917 	QT_TRAP_THROWING(refreshView(refreshListL()));	
   873 	delete mNote;
   918 	delete mNote;
   874 	mNote = NULL;
   919 	mNote = NULL;
   875 	}
   920 	RDEBUG("0", 0);
   876 
   921 	}
       
   922