cpsecplugins/cpadvancedsecplugin/src/cpmoduleview.cpp
changeset 63 989397f9511c
parent 62 3255e7d5bd67
child 66 67b3e3c1fc87
equal deleted inserted replaced
62:3255e7d5bd67 63:989397f9511c
     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 <mctauthobject.h>
       
    19 #include <mctkeystore.h>
       
    20 
       
    21 #include <qstringlist.h>
       
    22 #include <qgraphicslinearlayout.h>
       
    23 
       
    24 #include <hblineedit.h>
       
    25 #include <hbdataform.h>
       
    26 #include <hbdataformmodel.h>
       
    27 #include <hbdataformmodelitem.h>
       
    28 #include <hblabel.h>
       
    29 #include <hbpushbutton.h>
       
    30 #include <hbmenu.h>
       
    31 #include <hbaction.h>
       
    32 #include <hbmessagebox.h>
       
    33 #include <hblistwidget.h>
       
    34 #include <hblistwidgetitem.h>
       
    35 #include <hbgroupbox.h>
       
    36 #include <hbpushbutton.h>
       
    37 #include <hbdataform.h>
       
    38 #include <hbdataformmodel.h>
       
    39 #include <hbdataformmodelitem.h>
       
    40 #include <hbmainwindow.h>
       
    41 #include <hbabstractviewitem.h>
       
    42 
       
    43 #include <memory>
       
    44 #include <../../inc/cpsecplugins.h>
       
    45 #include "cpmoduleview.h"
       
    46 #include "cpsecmodmodel.h"
       
    47 #include "cpsecmodview.h"
       
    48 
       
    49 CpModuleView::CpModuleView( CpSecModView::TSecModViews currentView, 
       
    50 							CSecModUIModel& secModUIModel,
       
    51 							QGraphicsItem *parent /*= 0*/ )
       
    52 : CpBaseSettingView(0,parent),
       
    53   mCurrentView(currentView),
       
    54   mSecModUIModel(secModUIModel)
       
    55 	{
       
    56 	RDEBUG("0", 0);
       
    57 	QString title = mSecModUIModel.TokenLabelForTitle();
       
    58 	setTitle(title);
       
    59 	
       
    60 	mContextMenu = (q_check_ptr(new HbMenu()));
       
    61 	
       
    62 	if(currentView == CpSecModView::EAccessView)
       
    63 		{	
       
    64 		showAccessView();
       
    65 		}
       
    66 	else if(currentView == CpSecModView::ESignatureView)
       
    67 		{
       
    68 		showSignatureView(ETrue);
       
    69 		}
       
    70 	}
       
    71 
       
    72 CpModuleView::~CpModuleView()
       
    73 	{}
       
    74 
       
    75 void CpModuleView::showAccessView()
       
    76 	{
       
    77 	RDEBUG("0", 0);
       
    78 	HbMenu* menu = this->menu();   
       
    79 	std::auto_ptr<HbAction> endAction(q_check_ptr(new HbAction("Module Info")));     
       
    80 	connect(endAction.get(), SIGNAL(triggered()), this, SLOT(saveProv()));    
       
    81 
       
    82 	menu->addAction(endAction.get());
       
    83 	endAction.release();
       
    84 	
       
    85 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
       
    86 	
       
    87 	std::auto_ptr<HbDataForm> form(q_check_ptr(new HbDataForm()));
       
    88 	std::auto_ptr<HbDataFormModel> formModel(q_check_ptr(new HbDataFormModel()));
       
    89 	form->setModel(formModel.get());
       
    90 	formModel.release();
       
    91 	
       
    92 	QString titleName;
       
    93 	if (mSecModUIModel.KeyStoreUID() == KTokenTypeFileKeystore)
       
    94 		{
       
    95 		titleName = "Phone key store code";
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		const TDesC& label = mSecModUIModel.AuthObj(KPinGSettIndex).Label();
       
   100 		titleName = QString((QChar*)label.Ptr(), label.Length());
       
   101 		}
       
   102 	RDEBUG("0", 0);
       
   103 	HbListWidget* accessDetails = q_check_ptr(new HbListWidget(this)); 
       
   104 	
       
   105 	std::auto_ptr<HbListWidgetItem> codeLabel(q_check_ptr(new HbListWidgetItem()));
       
   106 	codeLabel->setText(titleName);
       
   107 	accessDetails->addItem(codeLabel.get());
       
   108 	codeLabel.release();
       
   109 
       
   110 	std::auto_ptr<HbListWidgetItem> codeText(q_check_ptr(new HbListWidgetItem()));
       
   111 	codeText->setText("****");
       
   112 	accessDetails->addItem(codeText.get());
       
   113 	codeText.release();
       
   114 
       
   115 	std::auto_ptr<HbListWidgetItem> requestLabel(q_check_ptr(new HbListWidgetItem()));
       
   116 	requestLabel->setText("Access Code Request");
       
   117 	accessDetails->addItem(requestLabel.get());
       
   118 	requestLabel.release();
       
   119 
       
   120 	TUint32 status = mSecModUIModel.AuthStatus(KPinGSettIndex);
       
   121 	std::auto_ptr<HbListWidgetItem> requestText(q_check_ptr(new HbListWidgetItem()));
       
   122 	requestText->setText("Off");
       
   123 	if (status & EEnabled)
       
   124 		{
       
   125 		requestText->setText("On");
       
   126 		}	
       
   127 	accessDetails->addItem(requestText.get());
       
   128 	requestText.release();
       
   129 	RDEBUG("0", 0);
       
   130 	std::auto_ptr<HbListWidgetItem> statusLabel(q_check_ptr(new HbListWidgetItem()));
       
   131 	statusLabel->setText("Status");
       
   132 	accessDetails->addItem(statusLabel.get());
       
   133 	statusLabel.release();
       
   134 	
       
   135 	std::auto_ptr<HbListWidgetItem> statusText(q_check_ptr(new HbListWidgetItem()));
       
   136 	QString pinStatus = mSecModUIModel.PINStatus(KPinGSettIndex, ETrue);
       
   137 	statusText->setText(pinStatus);
       
   138 	accessDetails->addItem(statusText.get());
       
   139 	statusText.release();
       
   140 
       
   141 	connect(accessDetails, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF)));
       
   142 	connect(formModel.get(), SIGNAL(activated(QModelIndex)), this, SLOT(handleAccessView(QModelIndex)));
       
   143 	
       
   144 	layout->addItem(accessDetails);	
       
   145 	layout->addItem(form.get());
       
   146 	form.release();
       
   147 	setLayout(layout.get());
       
   148 	layout.release();
       
   149 	RDEBUG("0", 0);
       
   150 	}
       
   151 
       
   152 void CpModuleView::showSignatureView(TBool showBlockedNote)
       
   153 	{
       
   154 	RDEBUG("0", 0);
       
   155 	mCurrentView = CpSecModView::ESignatureView;
       
   156 	std::auto_ptr<QGraphicsLinearLayout> layout(q_check_ptr(new QGraphicsLinearLayout(Qt::Vertical)));
       
   157 	std::auto_ptr<HbDataForm> form(q_check_ptr(new HbDataForm()));
       
   158 	std::auto_ptr<HbDataFormModel> formModel(q_check_ptr(new HbDataFormModel()));
       
   159 		
       
   160 	QVector< QPair<QString, TUint32> > authDetails = mSecModUIModel.AuthDetails();
       
   161 	QVectorIterator< QPair<QString, TUint32> > authDetailsIter(authDetails);
       
   162 	
       
   163 	HbListWidget* accessDetails = q_check_ptr(new HbListWidget(this)); 
       
   164 		
       
   165 	while(authDetailsIter.hasNext())
       
   166 		{
       
   167 		QPair<QString, TUint32> pair = authDetailsIter.next();
       
   168 		QString label = pair.first;
       
   169 		TUint32 status = pair.second;
       
   170 		QString blockedDetails = NULL;
       
   171 		if ( status & EAuthObjectBlocked)
       
   172 			{
       
   173 			if (showBlockedNote)
       
   174 				{
       
   175 				QString totalBlocked(" is blocked. PUK code is needed to unblock the code");
       
   176 				if (status & EUnblockDisabled)
       
   177 					{
       
   178 					totalBlocked =  " totalblocked, contact your module vendor.";
       
   179 					}
       
   180 				totalBlocked.prepend(label);
       
   181 				HbMessageBox::information(totalBlocked);
       
   182 				}
       
   183 			blockedDetails = label.append(" Blocked");
       
   184 		RDEBUG("0", 0);
       
   185 		std::auto_ptr<HbListWidgetItem> statusLabel(q_check_ptr(new HbListWidgetItem()));
       
   186 		statusLabel->setText(tr("Status"));
       
   187 		accessDetails->addItem(statusLabel.get());
       
   188 		statusLabel.release();
       
   189 
       
   190 		std::auto_ptr<HbListWidgetItem> statusText(q_check_ptr(new HbListWidgetItem()));
       
   191 		QString pinStatus = mSecModUIModel.PINStatus(KPinNrSettIndex, ETrue);
       
   192 		statusText->setText(pinStatus);
       
   193 		accessDetails->addItem(statusText.get());
       
   194 		statusText.release();
       
   195 		}
       
   196 		else
       
   197 			{
       
   198 			std::auto_ptr<HbListWidgetItem> unblockedLabel(q_check_ptr(new HbListWidgetItem()));
       
   199 			unblockedLabel->setText(label);
       
   200 			accessDetails->addItem(unblockedLabel.get());
       
   201 			unblockedLabel.release();
       
   202 			
       
   203 			std::auto_ptr<HbListWidgetItem> unblockedText(q_check_ptr(new HbListWidgetItem()));
       
   204 			unblockedText->setText("****");
       
   205 			accessDetails->addItem(unblockedText.get());
       
   206 			unblockedText.release();
       
   207 			}
       
   208 		}
       
   209 	form->setModel(formModel.get());
       
   210 	formModel.release();
       
   211 	layout->addItem(accessDetails);
       
   212 	
       
   213 	connect(accessDetails, SIGNAL(longPressed(HbAbstractViewItem*, QPointF )), this, SLOT(indicateLongPress(HbAbstractViewItem*, QPointF)));
       
   214 	connect(formModel.get(), SIGNAL(activated(QModelIndex)), this, SLOT(handleSigView()));
       
   215 		
       
   216 	layout->addItem(form.get());
       
   217 	form.release();
       
   218 	setLayout(layout.get());
       
   219 	layout.release();
       
   220 	RDEBUG("0", 0);
       
   221 	}
       
   222 
       
   223 void CpModuleView::indicateLongPress(HbAbstractViewItem *item,QPointF coords)
       
   224 	{
       
   225 	RDEBUG("0", 0);
       
   226 	try
       
   227 		{
       
   228 		mContextMenu->clearActions();
       
   229 		mPos = item->modelIndex().row();   
       
   230 		
       
   231 		if(mCurrentView == CpSecModView::EAccessView)
       
   232 			{
       
   233 			if( mPos == EIndexCodeLabel && mSecModUIModel.PinChangeable(KPinGSettIndex)
       
   234 				|| mPos == EIndexCodeRequest && mSecModUIModel.PinRequestChangeable(KPinGSettIndex)
       
   235 				|| mPos == EIndexCodeStatus )
       
   236 				{
       
   237 				std::auto_ptr<HbAction> changePIN(q_check_ptr(new HbAction("Change")));     
       
   238 				connect(changePIN.get(), SIGNAL(triggered()), this, SLOT( handleAccessView()));    
       
   239 				mContextMenu->addAction(changePIN.get());
       
   240 				changePIN.release();
       
   241 				}
       
   242 			if( mSecModUIModel.PinUnblockable(KPinGSettIndex) )
       
   243 				{
       
   244 				std::auto_ptr<HbAction> unblockPIN(q_check_ptr(new HbAction("Unblock")));     
       
   245 				connect(unblockPIN.get(), SIGNAL(triggered()), this, SLOT( handleAccessView()));    
       
   246 				mContextMenu->addAction(unblockPIN.get());
       
   247 				unblockPIN.release();
       
   248 				}
       
   249 			if( mSecModUIModel.PinOpen(KPinGSettIndex) )
       
   250 				{
       
   251 				std::auto_ptr<HbAction> closePIN(q_check_ptr(new HbAction("Close")));     
       
   252 				connect(closePIN.get(), SIGNAL(triggered()), this, SLOT( handleAccessView()));    
       
   253 				mContextMenu->addAction(closePIN.get());
       
   254 				closePIN.release();
       
   255 				}
       
   256 			}
       
   257 		else if(mCurrentView == CpSecModView::ESignatureView)
       
   258 			{
       
   259 			if (mSecModUIModel.PinChangeable(KPinNrSettIndex))
       
   260 				{
       
   261 				std::auto_ptr<HbAction> changePIN(q_check_ptr(new HbAction("Change")));     
       
   262 				connect(changePIN.get(), SIGNAL(triggered()), this, SLOT( handleSigViewCommand()));    
       
   263 				mContextMenu->addAction(changePIN.get());
       
   264 				changePIN.release();
       
   265 				}
       
   266 			if (mSecModUIModel.PinUnblockable(KPinNrSettIndex))
       
   267 				{
       
   268 				std::auto_ptr<HbAction> unblockPIN(q_check_ptr(new HbAction("Unblock")));     
       
   269 				connect(unblockPIN.get(), SIGNAL(triggered()), this, SLOT( handleSigViewCommand()));    
       
   270 				mContextMenu->addAction(unblockPIN.get());
       
   271 				unblockPIN.release();
       
   272 				}
       
   273 			}
       
   274 				
       
   275 		mContextMenu->setPreferredPos(coords);
       
   276 		mContextMenu->open();
       
   277 		}
       
   278 	catch(const std::exception& exception)
       
   279 		{
       
   280 		HbMessageBox::information(exception.what());
       
   281 		}
       
   282 	RDEBUG("0", 0);
       
   283 	}
       
   284 
       
   285 void CpModuleView::handleAccessView( const QModelIndex& modelIndex )
       
   286 	{
       
   287 	RDEBUG("0", 0);
       
   288 	try
       
   289 		{
       
   290 		mPos = modelIndex.row();
       
   291 		handleAccessView();
       
   292 		}
       
   293 	catch(const std::exception& exception)
       
   294 		{
       
   295 		HbMessageBox::information(exception.what());
       
   296 		}
       
   297 	}
       
   298 
       
   299 void CpModuleView::handleAccessView()
       
   300 	{
       
   301 	RDEBUG("0", 0);
       
   302 	try
       
   303 		{
       
   304 		if(mPos == EIndexCodeLabel)
       
   305 			{
       
   306 			QT_TRAP_THROWING(mSecModUIModel.ChangeOrUnblockPinL(KPinGSettIndex));        
       
   307 			}
       
   308 		else if(mPos == EIndexCodeRequest)
       
   309 			{
       
   310 			if (KErrCancel == mSecModUIModel.ChangeCodeRequest(KPinGSettIndex))
       
   311 				{
       
   312 				return;
       
   313 				}
       
   314 			}
       
   315 		else if ( mPos == EIndexCodeStatus)
       
   316 			{
       
   317 			QT_TRAP_THROWING(mSecModUIModel.CloseAuthObjL(KPinGSettIndex)); 
       
   318 			}
       
   319 		showAccessView();
       
   320 		}
       
   321 	catch(const std::exception& exception)
       
   322 		{
       
   323 		HbMessageBox::information(exception.what());
       
   324 		}
       
   325 	}
       
   326 
       
   327 void CpModuleView::handleSigView()
       
   328 	{
       
   329 	RDEBUG("0", 0);
       
   330 	try
       
   331 		{
       
   332 		QT_TRAP_THROWING(mSecModUIModel.ChangeOrUnblockPinL(KPinNrSettIndex));
       
   333 		showSignatureView(EFalse);
       
   334 		}
       
   335 	catch(const std::exception& exception)
       
   336 		{
       
   337 		HbMessageBox::information(exception.what());
       
   338 		}
       
   339 	}
       
   340 
       
   341 void CpModuleView::handleSigViewCommand()
       
   342 	{
       
   343 	RDEBUG("0", 0);
       
   344 	try
       
   345 		{
       
   346 		switch(mPos)
       
   347 			{
       
   348 			case ESecModUICmdChange:
       
   349 				QT_TRAP_THROWING(mSecModUIModel.ChangePinNrL(mPos));
       
   350 				showSignatureView(EFalse);
       
   351 				break;
       
   352 			case ESecModUICmdUnblock:
       
   353 				QT_TRAP_THROWING(mSecModUIModel.UnblockPinNrL(mPos));
       
   354 				showSignatureView(EFalse);
       
   355 				break;
       
   356 			};
       
   357 		}
       
   358 	catch(const std::exception& exception)
       
   359 		{
       
   360 		HbMessageBox::information(exception.what());
       
   361 		}
       
   362 	}
       
   363 
       
   364