securitydialogs/secuinotifications/secuinotificationdialogplugin/src/secuinotificationdialog.cpp
changeset 17 8957df7b0072
parent 15 318c4eab2439
child 19 098e361762d2
equal deleted inserted replaced
15:318c4eab2439 17:8957df7b0072
    20 #include "secuinotificationcontentwidget.h"
    20 #include "secuinotificationcontentwidget.h"
    21 // #include <hbpopupbase.h>        // HbPopupBase::NoTimeout
    21 // #include <hbpopupbase.h>        // HbPopupBase::NoTimeout
    22 #include <hblabel.h>
    22 #include <hblabel.h>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
    24 #include <QDebug>
    24 #include <QDebug>
       
    25 #include <e32debug.h>
       
    26 #include <CPhCltEmergencyCall.h>
       
    27 #include <SCPServerInterface.h>	// for TARM error codes while validating new lock code
       
    28 #include <QString>
       
    29 #include <QDialogButtonBox>
    25 
    30 
    26 #define ESecUiCancelSupported  0x1000000
    31 #define ESecUiCancelSupported  0x1000000
    27 #define ESecUiCancelNotSupported  0x0000000
    32 #define ESecUiCancelNotSupported  0x0000000
    28 
    33 
    29 #define ESecUiEmergencySupported  0x2000000
    34 #define ESecUiEmergencySupported  0x2000000
    30 #define ESecUiEmergencyNotSupported  0x0000000
    35 #define ESecUiEmergencyNotSupported  0x0000000
       
    36 
       
    37 #define ESecUiAlphaSupported  0x4000000
       
    38 #define ESecUiAlphaNotSupported  0x0000000
       
    39 
       
    40 #define ESecUiMaskFlags  0xFF000000
       
    41 #define ESecUiMaskType   0x00FFFFFF
       
    42 
       
    43 #define ESecUiTypeDeviceLock		0x00100000
       
    44 #define ESecUiTypeKeyguard			0x00200000
       
    45 #define ESecUiTypeClock  				0x00300000
       
    46 #define ESecUiTypeScreensaver		0x00400000
       
    47 
       
    48 #define ESecUiTypeMaskLock			0x00F00000
    31 
    49 
    32 // ----------------------------------------------------------------------------
    50 // ----------------------------------------------------------------------------
    33 // SecUiNotificationDialog::SecUiNotificationDialog()
    51 // SecUiNotificationDialog::SecUiNotificationDialog()
    34 // ----------------------------------------------------------------------------
    52 // ----------------------------------------------------------------------------
    35 //
    53 //
   129     setModal(true);
   147     setModal(true);
   130 
   148 
   131     // Title
   149     // Title
   132     if (parameters.contains(KDialogTitle)) {
   150     if (parameters.contains(KDialogTitle)) {
   133         QString titleText = parameters.value(KDialogTitle).toString();
   151         QString titleText = parameters.value(KDialogTitle).toString();
   134         HbLabel *title = new HbLabel(titleText);
   152         QString titleAttempts = "";
       
   153    			if(titleText.indexOf('|')>0)
       
   154     				{	// if separator, take only first part
       
   155     				titleText = titleText.left(titleText.indexOf('|'));
       
   156     				}
       
   157    			if(titleText.indexOf('#')>0)
       
   158     				{	// if separator, take only first part
       
   159     				titleAttempts = titleText.right(titleText.length()-titleText.indexOf('#')-1);
       
   160     				qDebug() << "SecUiNotificationDialog::titleAttempts=" << titleAttempts;
       
   161     				int nAttempts = titleAttempts.toInt();
       
   162     				qDebug() << "SecUiNotificationDialog::nAttempts=" << nAttempts;
       
   163     				titleText = titleText.left(titleText.indexOf('#'));
       
   164     				if(nAttempts>0)
       
   165     					titleText = titleText + " attempts=" + QString::number(nAttempts);
       
   166     				}
       
   167         title = new HbLabel(titleText);
   135         setHeadingWidget(title);
   168         setHeadingWidget(title);
   136     }
   169     }
   137 
   170 
       
   171 	    if (parameters.contains(KEmergency)) {
       
   172 					qDebug() << "SecUiNotificationDialog::KEmergency";
       
   173 	        QString emergencyText = parameters.value(KEmergency).toString();
       
   174 	        qDebug() << emergencyText;
       
   175 	        if(!emergencyText.compare("emergencyYes"))
       
   176 	        	{
       
   177 	        	qDebug() << "SecUiNotificationDialog::KEmergency emergencyYes";
       
   178 	        	isEmergency = 1;
       
   179 	        	okAction->setEnabled(true);
       
   180 	        	okAction->setText("Call");
       
   181     				return true;
       
   182 	        	}
       
   183 	        if(!emergencyText.compare("emergencyNo"))
       
   184 	        	{
       
   185 	        	qDebug() << "SecUiNotificationDialog::KEmergency emergencyNo";
       
   186 	        	isEmergency = 0;
       
   187 	        	okAction->setEnabled(false);	// 112 -> 1122 (=password) . This is handled by   < lMinLength 
       
   188 	        	okAction->setText("Ok");
       
   189     				return true;
       
   190 	        	}
       
   191 	    }
       
   192 	    
       
   193 	    if (parameters.contains(KInvalidNewLockCode)) {
       
   194 					qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode";
       
   195 	        QString invalidText = parameters.value(KInvalidNewLockCode).toString();
       
   196 	        qDebug() << invalidText;
       
   197 
       
   198 	        title->setPlainText("Lock Code");	// TODO take from the original one
       
   199 	        QString invalidStr = invalidText.right(invalidText.length()-invalidText.indexOf('#')-1);
       
   200 	        int invalidNumber = invalidStr.toInt();
       
   201 	        qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode invalidNumber" << invalidNumber;
       
   202 	        if(invalidNumber<0)
       
   203 	        	{
       
   204 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode ???";
       
   205 	        	// nothing to do
       
   206 	        	}
       
   207 /*
       
   208 	        if(invalidNumber==EDeviceLockAutolockperiod)
       
   209 	        	{
       
   210 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAutolockperiod";
       
   211 	        	title->setPlainText("EDeviceLockAutolockperiod");
       
   212 	        	}
       
   213 	        if(invalidNumber==EDeviceLockMaxAutolockPeriod)
       
   214 	        	{
       
   215 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMaxAutolockPeriod";
       
   216 	        	title->setPlainText("EDeviceLockMaxAutolockPeriod");
       
   217 	        	}
       
   218 	        if(invalidNumber==EDeviceLockMinlength)
       
   219 	        	{
       
   220 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinlength";
       
   221 	        	title->setPlainText("EDeviceLockMinlength");
       
   222 	        	}
       
   223 	        if(invalidNumber==EDeviceLockMaxlength)
       
   224 	        	{
       
   225 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMaxlength";
       
   226 	        	title->setPlainText("EDeviceLockMaxlength");
       
   227 	        	}
       
   228 	        if(invalidNumber==EDeviceLockRequireUpperAndLower)
       
   229 	        	{
       
   230 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockRequireUpperAndLower";
       
   231 	        	title->setPlainText("EDeviceLockRequireUpperAndLower");
       
   232 	        	}
       
   233 	        if(invalidNumber==EDeviceLockRequireCharsAndNumbers)
       
   234 	        	{
       
   235 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockRequireCharsAndNumbers";
       
   236 	        	title->setPlainText("EDeviceLockMaxlength");
       
   237 	        	}
       
   238 	        if(invalidNumber==EDeviceLockAllowedMaxRepeatedChars)
       
   239 	        	{
       
   240 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAllowedMaxRepeatedChars";
       
   241 	        	title->setPlainText("EDeviceLockAllowedMaxRepeatedChars");
       
   242 	        	}
       
   243 	        if(invalidNumber==EDeviceLockHistoryBuffer)
       
   244 	        	{
       
   245 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockHistoryBuffer";
       
   246 	        	title->setPlainText("EDeviceLockHistoryBuffer");
       
   247 	        	}
       
   248 	        if(invalidNumber==EDeviceLockPasscodeExpiration)
       
   249 	        	{
       
   250 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockPasscodeExpiration";
       
   251 	        	title->setPlainText("EDeviceLockPasscodeExpiration");
       
   252 	        	}
       
   253 	        if(invalidNumber==EDeviceLockMinChangeTolerance)
       
   254 	        	{
       
   255 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinChangeTolerance";
       
   256 	        	title->setPlainText("EDeviceLockMinChangeTolerance");
       
   257 	        	}
       
   258 	        if(invalidNumber==EDeviceLockMinChangeInterval)
       
   259 	        	{
       
   260 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinChangeInterval";
       
   261 	        	title->setPlainText("EDeviceLockMinChangeInterval");
       
   262 	        	}
       
   263 	        if(invalidNumber==EDeviceLockDisallowSpecificStrings)
       
   264 	        	{
       
   265 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockDisallowSpecificStrings";
       
   266 	        	title->setPlainText("EDeviceLockDisallowSpecificStrings");
       
   267 	        	}
       
   268 	        if(invalidNumber==EDeviceLockAllowedMaxAtempts)
       
   269 	        	{
       
   270 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAllowedMaxAtempts";
       
   271 	        	title->setPlainText("EDeviceLockAllowedMaxAtempts");
       
   272 	        	}
       
   273 	        if(invalidNumber==EDeviceLockConsecutiveNumbers)
       
   274 	        	{
       
   275 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockConsecutiveNumbers";
       
   276 	        	title->setPlainText("EDeviceLockConsecutiveNumbers");
       
   277 	        	}
       
   278 	        if(invalidNumber==EDeviceLockMinSpecialCharacters)
       
   279 	        	{
       
   280 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinSpecialCharacters";
       
   281 	        	title->setPlainText("EDeviceLockMinSpecialCharacters");
       
   282 	        	}
       
   283 	        if(invalidNumber==EDeviceLockSingleCharRepeatNotAllowed)
       
   284 	        	{
       
   285 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockSingleCharRepeatNotAllowed";
       
   286 	        	title->setPlainText("EDeviceLockSingleCharRepeatNotAllowed");
       
   287 	        	}
       
   288 	        if(invalidNumber==EDevicelockConsecutiveCharsNotAllowed)
       
   289 	        	{
       
   290 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDevicelockConsecutiveCharsNotAllowed";
       
   291 	        	title->setPlainText("EDevicelockConsecutiveCharsNotAllowed");
       
   292 	        	}
       
   293 	        if(invalidNumber>=EDevicelockTotalPolicies)
       
   294 	        	{
       
   295 	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDevicelockTotalPolicies";
       
   296 	        	title->setPlainText("EDevicelockTotalPolicies");
       
   297 	        	}
       
   298 	        	*/
       
   299 	        // always keep OK valid.
       
   300    				return true;
       
   301 	    }
       
   302 	
   138     // Content
   303     // Content
   139     SecUiNotificationContentWidget *content = new SecUiNotificationContentWidget();
   304     SecUiNotificationContentWidget *content = new SecUiNotificationContentWidget();
   140     content->constructFromParameters(parameters);
   305     content->constructFromParameters(parameters);
   141     setContentWidget(content);
   306     setContentWidget(content);
       
   307 
       
   308 		queryType = content->queryType;
       
   309 		queryDual = content->queryDual;
       
   310 		isEmergency = content->isEmergency;
       
   311 		codeTop = content->codeTop;
       
   312 		codeBottom = content->codeBottom;
       
   313 		lMinLength = content->lMinLength;
       
   314 		lMaxLength = content->lMaxLength;
       
   315 		lEmergencySupported = content->lEmergencySupported;
       
   316 
   142     connect(content, SIGNAL(codeTopChanged(const QString &)), this, SLOT(handleCodeTopChanged(const QString &)));
   317     connect(content, SIGNAL(codeTopChanged(const QString &)), this, SLOT(handleCodeTopChanged(const QString &)));
       
   318     connect(content, SIGNAL(codeBottomChanged(const QString &)), this, SLOT(handleCodeBottomChanged(const QString &)));
   143     connect(content, SIGNAL(but1Changed()), this, SLOT(handlebut1Changed()));
   319     connect(content, SIGNAL(but1Changed()), this, SLOT(handlebut1Changed()));
   144     connect(content, SIGNAL(but2Changed()), this, SLOT(handlebut2Changed()));
   320     connect(content, SIGNAL(but2Changed()), this, SLOT(handlebut2Changed()));
   145     connect(content, SIGNAL(but3Changed()), this, SLOT(handlebut3Changed()));
   321     connect(content, SIGNAL(but3Changed()), this, SLOT(handlebut3Changed()));
   146 		codeTop = content->codeTop;
       
   147 		queryType = content->queryType;
       
   148 		qDebug() << "SecUiNotificationDialog::queryType=";
   322 		qDebug() << "SecUiNotificationDialog::queryType=";
   149 		qDebug() << queryType;
   323 		qDebug() << queryType;
   150     // Buttons
   324     // Buttons
   151     okAction = new HbAction(tr("Ok"));            // qtTrId("txt_common_button_ok")
   325     if( (queryType & ESecUiTypeMaskLock))
       
   326     	{
       
   327     	// no need to create OK or Cancel
       
   328     	return true;
       
   329     	}
       
   330 
       
   331     okAction = new HbAction(tr("Ok"));
       
   332     okAction->setEnabled(false);	// initially the OK is disabled because codeTop is empty
       
   333     // setAction(okAction, QDialogButtonBox::AcceptRole);	// it's supposed to use this, when deprecated
   152     setPrimaryAction(okAction);
   334     setPrimaryAction(okAction);
   153     connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   335     connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
       
   336     
   154     cancelAction = new HbAction(tr("Cancel"));    // qtTrId("txt_common_button_cancel")
   337     cancelAction = new HbAction(tr("Cancel"));    // qtTrId("txt_common_button_cancel")
   155     connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
   338     connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
       
   339     // setAction(cancelAction, QDialogButtonBox::RejectRole);		// it's supposed to use this, when deprecated
   156     setSecondaryAction(cancelAction);
   340     setSecondaryAction(cancelAction);
   157 
   341 
   158 		qDebug() << "SecUiNotificationDialog check Cancel";
   342 		qDebug() << "SecUiNotificationDialog check Cancel";
   159     if (queryType & ESecUiCancelSupported)
   343     if ((queryType & ESecUiCancelSupported)==ESecUiCancelSupported)
   160     	{
   344     	{
   161     		// nothing to do. Cancel is enabled by default
   345     		// nothing to do. Cancel is enabled by default
   162     	}
   346     	}
   163   	else
   347   	else
   164   		{
   348   		{
   171 
   355 
   172 // ----------------------------------------------------------------------------
   356 // ----------------------------------------------------------------------------
   173 // SecUiNotificationDialog::sendResult()
   357 // SecUiNotificationDialog::sendResult()
   174 // ----------------------------------------------------------------------------
   358 // ----------------------------------------------------------------------------
   175 //
   359 //
   176 void SecUiNotificationDialog::sendResult(bool accepted)
   360 void SecUiNotificationDialog::sendResult(int accepted)
   177 {
   361 {
   178 		qDebug() << "SecUiNotificationDialog::sendResult 1.2";
   362 		qDebug() << "SecUiNotificationDialog::sendResult 1.2";
   179     QVariant acceptedValue(accepted);
   363     QVariant acceptedValue(accepted);
   180 		qDebug() << "SecUiNotificationDialog::sendResult 2";
   364 		qDebug() << "SecUiNotificationDialog::sendResult 2";
   181     mResultMap.insert(KResultAccepted, acceptedValue);
   365     mResultMap.insert(KResultAccepted, acceptedValue);
   191 //
   375 //
   192 void SecUiNotificationDialog::handleAccepted()
   376 void SecUiNotificationDialog::handleAccepted()
   193 {
   377 {
   194 		qDebug() << "SecUiNotificationDialog::handleAccepted";
   378 		qDebug() << "SecUiNotificationDialog::handleAccepted";
   195 		// okAction
   379 		// okAction
   196 		QString codeTopText = codeTop->text();
   380 		QString codeTopText;
   197    	qDebug() << "codeTopText";
   381 
   198    	qDebug() << codeTopText;
   382 		if( (queryType & ESecUiTypeMaskLock))
   199 		if(!codeTopText.compare("1234111"))
   383     	{
   200 				{
   384     	codeTopText = "Unlock-Request";
   201 					qDebug() << "codeTopText is 1234111. Not exit";
   385     	}
   202 					return;
   386     else
   203 				}
   387     	{
   204     sendResult(true);
   388     	codeTopText = codeTop->text();
       
   389     	}
       
   390     // TODO check last time for codeBottom
       
   391    	qDebug() << "codeTopText=" << codeTopText;
       
   392     sendResult(KErrNone);
   205 }
   393 }
   206 
   394 
   207 // ----------------------------------------------------------------------------
   395 // ----------------------------------------------------------------------------
   208 // SecUiNotificationDialog::handleCancelled()
   396 // SecUiNotificationDialog::handleCancelled()
   209 // ----------------------------------------------------------------------------
   397 // ----------------------------------------------------------------------------
   210 //
   398 //
   211 void SecUiNotificationDialog::handleCancelled()
   399 void SecUiNotificationDialog::handleCancelled()
   212 {
   400 {
   213 		qDebug() << "SecUiNotificationDialog::handleCancelled";
   401 		qDebug() << "SecUiNotificationDialog::handleCancelled";
   214     sendResult(false);
   402     sendResult(KErrCancel);
   215 }
   403 }
   216 
   404 
   217 // ----------------------------------------------------------------------------
   405 // ----------------------------------------------------------------------------
   218 // SecUiNotificationDialog::handleMemorySelectionChanged()
   406 // SecUiNotificationDialog::handleMemorySelectionChanged()
   219 // ----------------------------------------------------------------------------
   407 // ----------------------------------------------------------------------------
   233 // ----------------------------------------------------------------------------
   421 // ----------------------------------------------------------------------------
   234 //
   422 //
   235 void SecUiNotificationDialog::handleCodeTopChanged(const QString &text)
   423 void SecUiNotificationDialog::handleCodeTopChanged(const QString &text)
   236     {
   424     {
   237     	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged";
   425     	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged";
   238     	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged" << text ;
   426     	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged=" << text ;
       
   427     	if(queryDual)
       
   428     		{
       
   429     		codeBottom->setText("");	// any change resets the verification.
       
   430     		}
       
   431     	if( queryType == 0x1000004 )
       
   432     		{	// ChangeSecCodeParamsL change RMobilePhone::ESecurityCodePhonePassword
       
   433 			    QVariant codeTop(text);
       
   434 			    mResultMap.insert(KCodeTopIndex, codeTop);
       
   435 					sendResult(KErrCompletion);	// send the current password back to the client for further TARM validation
       
   436     		}
       
   437     	if(text.length() < lMinLength )
       
   438     		{
       
   439     		qDebug() << "SecUiNotificationDialog::handleCodeTopChanged too short:" << text ;
       
   440     		okAction->setEnabled(false);
       
   441 
       
   442 				if( lEmergencySupported && text.length() > 2 )	// emergency numbers need at least 3 digits
       
   443 					{	// check whether it's a emergency number
       
   444 					QVariant codeTop(text);
       
   445   				mResultMap.insert(KCodeTopIndex, codeTop);
       
   446 					sendResult(KErrAbort);	// send the current password back to the client. Perhaps it's an emergency number and decides to Ok->Call
       
   447 					}
       
   448     		}
       
   449     	else if (text.length() >= lMinLength)
       
   450     		{
       
   451     		// TODO might use a flag to avoid re-setting
       
   452     		qDebug() << "SecUiNotificationDialog::handleCodeTopChanged long enough:" << text ;
       
   453     		okAction->setText("Ok");
       
   454     		if(queryDual==0)	// only if Bottom is not used
       
   455     			okAction->setEnabled(true);
       
   456     		}
   239     QVariant codeTop(text);
   457     QVariant codeTop(text);
   240     mResultMap.insert(KCodeTopIndex, codeTop);
   458     mResultMap.insert(KCodeTopIndex, codeTop);
       
   459     }
       
   460 // ----------------------------------------------------------------------------
       
   461 // SecUiNotificationDialog::handleCodeBottomChanged()
       
   462 // ----------------------------------------------------------------------------
       
   463 //
       
   464 void SecUiNotificationDialog::handleCodeBottomChanged(const QString &text)
       
   465     {
       
   466     	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged";
       
   467     	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged" << text ;
       
   468     	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged. codeTop=" << codeTop->text() ;
       
   469     	// TODO compare 
       
   470     	if(text.length() < lMinLength )
       
   471     		{
       
   472     		qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged too short:" << text ;
       
   473     		okAction->setEnabled(false);
       
   474     		}
       
   475     	else
       
   476     		{
       
   477     		// TODO might use a flag to avoid re-setting
       
   478     		qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged long enough:" << text ;
       
   479     		if(codeTop->text()==text)
       
   480     			{
       
   481     			qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged codes match:" << text ;
       
   482 	    		okAction->setEnabled(true);
       
   483 	    		}
       
   484 	    	else
       
   485 	    		{
       
   486     			qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged codes not match:" << text ;
       
   487 					okAction->setEnabled(false);
       
   488 	    		}
       
   489     		}
       
   490 		// verification is not sent
   241     }
   491     }
   242 // ----------------------------------------------------------------------------
   492 // ----------------------------------------------------------------------------
   243 // SecUiNotificationDialog::handlebut1Changed()
   493 // SecUiNotificationDialog::handlebut1Changed()
   244 // ----------------------------------------------------------------------------
   494 // ----------------------------------------------------------------------------
   245 //
   495 //