securitydialogs/secuinotifications/secuinotificationdialogplugin/src/secuinotificationdialog.cpp
branchRCL_3
changeset 22 03674e5abf46
parent 21 09b1ac925e3f
child 23 94da73d93b58
equal deleted inserted replaced
21:09b1ac925e3f 22:03674e5abf46
     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: SecUi notification plugin class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "secuinotificationdebug.h"
       
    19 #include "secuinotificationdialog.h"
       
    20 #include "secuinotificationdialogpluginkeys.h"
       
    21 #include "secuinotificationcontentwidget.h"
       
    22 // #include <hbpopupbase.h>        // HbPopupBase::NoTimeout
       
    23 #include <hblabel.h>
       
    24 #include <hbaction.h>
       
    25 #include <QDebug>
       
    26 #include <e32debug.h>
       
    27 #include <hbtranslator.h>
       
    28 #include <cphcltemergencycall.h>
       
    29 #include <SCPServerInterface.h>	// for TARM error codes while validating new lock code
       
    30 #include <QString>
       
    31 #include <QDialogButtonBox>
       
    32 #include <HbEditorInterface>
       
    33 #include <e32property.h>
       
    34 
       
    35 QTM_USE_NAMESPACE
       
    36 
       
    37 const QString KTranslationsPath = "/resource/qt/translations/";
       
    38 const QString KSecUiNotificationTranslationsFile = "secui";
       
    39 const QString KCommonTranslationsFile = "common";
       
    40 
       
    41 #include <qvaluespacesubscriber.h>
       
    42 #include <qvaluespacepublisher.h>
       
    43 #define ESecUiBasicTypeText    0x0000000
       
    44 #define ESecUiBasicTypeCheck   0x0010000
       
    45 #define ESecUiBasicTypeCheckMulti   0x0020000
       
    46 #define ESecUiBasicTypeMask    0x00F0000
       
    47 
       
    48 #define ESecUiCancelSupported  0x1000000
       
    49 #define ESecUiCancelNotSupported  0x0000000
       
    50 
       
    51 #define ESecUiEmergencySupported  0x2000000
       
    52 #define ESecUiEmergencyNotSupported  0x0000000
       
    53 
       
    54 #define ESecUiAlphaSupported  0x4000000
       
    55 #define ESecUiAlphaNotSupported  0x0000000
       
    56 
       
    57 #define ESecUiSecretSupported  0x8000000
       
    58 #define ESecUiSecretNotSupported  0x0000000
       
    59 
       
    60 #define ESecUiMaskFlags  0xFF000000
       
    61 #define ESecUiMaskType   0x00FFFFFF
       
    62 
       
    63 #define ESecUiTypeDeviceLock		0x00100000
       
    64 #define ESecUiTypeKeyguard			0x00200000
       
    65 #define ESecUiTypeClock  				0x00300000
       
    66 #define ESecUiTypeScreensaver		0x00400000
       
    67 
       
    68 #define ESecUiTypeMaskLock			0x00F00000
       
    69 
       
    70 const TUid KPSUidSecurityUIs = { 0x100059b5 };
       
    71 const TUint32 KSecurityUIsDismissDialog  = 0x00000309;
       
    72 
       
    73 enum TSecurityUIsDismissDialogValues
       
    74     {
       
    75     ESecurityUIsDismissDialogUninitialized = 0,
       
    76     ESecurityUIsDismissDialogOn,
       
    77     ESecurityUIsDismissDialogProcessing,
       
    78     ESecurityUIsDismissDialogDone,
       
    79     ESecurityUIsDismissDialogLastValue
       
    80     };
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // SecUiNotificationDialog::SecUiNotificationDialog()
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 SecUiNotificationDialog::SecUiNotificationDialog(
       
    87         const QVariantMap &parameters) : HbDialog(), mCommonTranslator(0), mSecUiNotificationTranslator(0), mLastError(KNoError)
       
    88 {
       
    89 		RDEBUG("0", 0);
       
    90 		TTime myTime;
       
    91     myTime.HomeTime();
       
    92 		mMyId = I64LOW( myTime.Int64() );
       
    93     mCommonTranslator = new HbTranslator(KTranslationsPath, KCommonTranslationsFile);
       
    94     mSecUiNotificationTranslator = new HbTranslator(KTranslationsPath, KSecUiNotificationTranslationsFile);
       
    95     constructDialog(parameters);
       
    96 }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // SecUiNotificationDialog::~SecUiNotificationDialog()
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 SecUiNotificationDialog::~SecUiNotificationDialog()
       
   103 {
       
   104 		RDEBUG("0", 0);
       
   105     delete mSecUiNotificationTranslator;
       
   106     delete mCommonTranslator;
       
   107 		RDEBUG("0", 0);
       
   108     // TODO what about subscriberKSecurityUIsDismissDialog
       
   109     // and codeTop
       
   110 		RDEBUG("1", 1);
       
   111 }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // SecUiNotificationDialog::setDeviceDialogParameters()
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 bool SecUiNotificationDialog::setDeviceDialogParameters(const QVariantMap &parameters)
       
   118 {
       
   119 	 RDEBUG("0", 0);
       
   120    return constructDialog(parameters);
       
   121 }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // SecUiNotificationDialog::deviceDialogError()
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 int SecUiNotificationDialog::deviceDialogError() const
       
   128 {
       
   129 		RDEBUG("mLastError", mLastError);
       
   130 		RDEBUG("mMyId", mMyId);
       
   131     return mLastError;
       
   132 }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // SecUiNotificationDialog::closeDeviceDialog
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 void SecUiNotificationDialog::closeDeviceDialog(bool byClient)
       
   139 {
       
   140     Q_UNUSED(byClient);
       
   141 		RDEBUG("mMyId", mMyId);
       
   142 		RDEBUG("calling close()", 0);
       
   143     close();
       
   144 		RDEBUG("mShowEventReceived", mShowEventReceived);
       
   145 
       
   146     // If show event has been received, close is signalled from hide event.
       
   147     // If not, hide event does not come and close is signalled from here.
       
   148     if (!mShowEventReceived) {
       
   149     		RDEBUG("emitting deviceDialogClosed", 0);
       
   150         emit deviceDialogClosed();
       
   151 				if(1==0 && subscriberKSecurityUIsDismissDialog)
       
   152 					{
       
   153 						RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
       
   154 						disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   155 						RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
       
   156 						if(1==1)
       
   157 							{
       
   158 							RDEBUG("deleting subscriberKSecurityUIsDismissDialog", 0);
       
   159 							delete subscriberKSecurityUIsDismissDialog;
       
   160 							subscriberKSecurityUIsDismissDialog = NULL;
       
   161 							RDEBUG("deleted subscriberKSecurityUIsDismissDialog", 1);
       
   162 							}
       
   163 				 }
       
   164     }
       
   165     RDEBUG("0", 0);
       
   166 }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // SecUiNotificationDialog::deviceDialogWidget
       
   170 // ----------------------------------------------------------------------------
       
   171 //
       
   172 HbDialog *SecUiNotificationDialog::deviceDialogWidget() const
       
   173 {
       
   174     return const_cast<SecUiNotificationDialog*>(this);
       
   175 }
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // SecUiNotificationDialog::hideEvent
       
   179 // ----------------------------------------------------------------------------
       
   180 //
       
   181 void SecUiNotificationDialog::hideEvent(QHideEvent *event)
       
   182 {
       
   183 		RDEBUG("0", 0);
       
   184     HbDialog::hideEvent(event);
       
   185 		RDEBUG("mMyId", mMyId);
       
   186 		RDEBUG("calling close()", 0);
       
   187 		close();
       
   188 		RDEBUG("emitting deviceDialogClosed", 0);
       
   189 		emit deviceDialogClosed();
       
   190 		RDEBUG("deviceDialogClosed", 1);
       
   191 		if(1==0 && subscriberKSecurityUIsDismissDialog)
       
   192 			{
       
   193 				RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
       
   194 				disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   195 				RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
       
   196 				if(1==1)
       
   197 					{ 
       
   198 					RDEBUG("deleting subscriberKSecurityUIsDismissDialog", 0);
       
   199 					delete subscriberKSecurityUIsDismissDialog;
       
   200 					subscriberKSecurityUIsDismissDialog = NULL;
       
   201 					RDEBUG("deleted subscriberKSecurityUIsDismissDialog", 1);
       
   202 					}
       
   203 			}
       
   204     // old method was   emit deviceDialogClosed();
       
   205    RDEBUG("0", 0);
       
   206 }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // SecUiNotificationDialog::showEvent
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 void SecUiNotificationDialog::showEvent(QShowEvent *event)
       
   213 {
       
   214 		RDEBUG("0", 0);
       
   215 		RDEBUG("mMyId", mMyId);
       
   216     HbDialog::showEvent(event);
       
   217 
       
   218 		if(!(queryType & ESecUiTypeMaskLock))
       
   219 			{	// not for the "lock icon"
       
   220 			RDEBUG("check default.1", 0);
       
   221 			if(codeTop!=NULL)
       
   222             {
       
   223             RDEBUG("check default.2", 0);
       
   224             if(codeTop->text().length()>0)	// there's a default value. Verify it and (might) enable OK
       
   225                 {
       
   226                 RDEBUG("check default.3", 0);
       
   227                 handleCodeTopChanged(codeTop->text());
       
   228                 }
       
   229             RDEBUG("setFocus", 0);
       
   230         		// remove setFocus from PIN query because Orbit can't handle it
       
   231       			// codeTop->setFocus();	// this should open the VKB . Doesn't seem to work when it's done on the widget, so it's done here.
       
   232             }	// codeTop!=NULL
       
   233             
       
   234 			const TUint32 KSecurityUIsTestCode  = 0x00000307;
       
   235 			TInt value = 0;
       
   236 			TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsTestCode, value );
       
   237 			RDEBUG("KSecurityUIsTestCode err", err);
       
   238 			RDEBUG("faking value", value);
       
   239 			RDEBUG("mShowEventReceived", mShowEventReceived);
       
   240 			if(value>0 && value<1000000 && mShowEventReceived==true)	// show happens 2 times. Dialog can be closed only the second.
       
   241 				{
       
   242 				QString myString = "";
       
   243 				myString += QString("%1").arg(value);
       
   244 				RDEBUGQT("myString", myString);
       
   245 		    codeTop->setText( myString );
       
   246 		    TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsTestCode, 0 );	// clear after using it
       
   247 		    RDEBUGQT("calling handleAccepted myString", myString);
       
   248 		    emit handleAccepted();
       
   249 				// handleAccepted already   emit closeDeviceDialog(false);	// false means "not by client", although it's not really used
       
   250 				}
       
   251 			}
       
   252     mShowEventReceived = true;
       
   253     RDEBUG("1", 1);
       
   254 }
       
   255 
       
   256 // ----------------------------------------------------------------------------
       
   257 // SecUiNotificationDialog::constructDialog()
       
   258 // ----------------------------------------------------------------------------
       
   259 //
       
   260 bool SecUiNotificationDialog::constructDialog(const QVariantMap &parameters)
       
   261     {
       
   262 		RDEBUG("0", 0);
       
   263 		RDEBUG("mMyId", mMyId);
       
   264     setTimeout(HbPopup::NoTimeout);
       
   265     setDismissPolicy(HbPopup::NoDismiss);
       
   266     setModal(true);
       
   267     mShowEventReceived = false;
       
   268     subscriberKSecurityUIsDismissDialog = NULL;
       
   269     titleWidget = NULL;
       
   270 		RDEBUG("subscriberKSecurityUIsDismissDialog NULL", 0);
       
   271 
       
   272     subscriberKSecurityUIsDismissDialog = new QValueSpaceSubscriber("/KPSUidSecurityUIs/KSecurityUIsDismissDialog", this);
       
   273     if(subscriberKSecurityUIsDismissDialog)
       
   274     	{
       
   275     	RDEBUG("subscriberKSecurityUIsDismissDialog created", 1);
       
   276     	}
       
   277     else
       
   278     	{
       
   279     	RDEBUG("subscriberKSecurityUIsDismissDialog not created", 0);
       
   280     	}
       
   281     connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   282 		RDEBUG("subscriberKSecurityUIsDismissDialog", 1);
       
   283 
       
   284     // Title
       
   285     // this is also done later in the widget
       
   286     // For now, it only says "Security"
       
   287     if (parameters.contains(KDialogTitle)) {
       
   288         QString titleText = parameters.value(KDialogTitle).toString();
       
   289         QString titleAttempts = "";
       
   290    			if(titleText.indexOf('|')>0)
       
   291     				{	// if separator, take only first part
       
   292     				titleText = titleText.left(titleText.indexOf('|'));
       
   293     				}
       
   294    			if(titleText.indexOf('$')>0)
       
   295     				{	// if separator, take only first part
       
   296     				titleAttempts = titleText.right(titleText.length()-titleText.indexOf('$')-1);
       
   297     				RDEBUGQT("titleAttempts", titleAttempts);
       
   298     				int nAttempts = titleAttempts.toInt();
       
   299     				RDEBUG("nAttempts", nAttempts);
       
   300     				titleText = titleText.left(titleText.indexOf('$'));
       
   301     				if(nAttempts>0)
       
   302     					titleText = titleText + " attempts=" + QString::number(nAttempts);
       
   303     				}
       
   304     		titleText = hbTrId("Security Query");	// this is the header, for any potential later error which needs to be displayed
       
   305         // This is created only if needed (i.e. errors for NewLockCode)
       
   306         // titleWidget = new HbLabel(titleText);
       
   307         // setHeadingWidget(titleWidget);
       
   308     }
       
   309 
       
   310 	    if (parameters.contains(KEmergency)) {
       
   311 					RDEBUG("KEmergency", 1);
       
   312 	        QString emergencyText = parameters.value(KEmergency).toString();
       
   313 	        RDEBUGQT("emergencyText", emergencyText);
       
   314 	        if(!emergencyText.compare("emergencyYes"))
       
   315 	        	{
       
   316 	        	RDEBUG("emergencyYes", 1);
       
   317 	        	isEmergency = 1;
       
   318 	        	okAction->setEnabled(true);
       
   319 	        	okAction->setText(hbTrId("Call"));
       
   320     				return true;
       
   321 	        	}
       
   322 	        if(!emergencyText.compare("emergencyNo"))
       
   323 	        	{
       
   324 	        	RDEBUG("emergencyNo", 1);
       
   325 	        	isEmergency = 0;
       
   326 	        	okAction->setEnabled(false);	// 112 -> 1122 (=password) . This is handled by   < lMinLength 
       
   327 	        	okAction->setText(hbTrId("Ok"));
       
   328     				return true;
       
   329 	        	}
       
   330 	    }
       
   331 	    // after TARM validation.
       
   332 	    if (parameters.contains(KInvalidNewLockCode)) {
       
   333 					RDEBUG("KInvalidNewLockCode", 0);
       
   334 	        QString invalidText = parameters.value(KInvalidNewLockCode).toString();
       
   335 	        RDEBUGQT("invalidText", invalidText);
       
   336 	        QString newTitleText = "Lock Code";	// TODO take from the original one
       
   337 
       
   338 	        QString invalidStr = invalidText.right(invalidText.length()-invalidText.indexOf('$')-1);
       
   339 	        int invalidNumber = invalidStr.toInt();
       
   340 	        RDEBUG("invalidNumber", invalidNumber);
       
   341 	        if(invalidNumber<0)	// that is, -1
       
   342 	        	{
       
   343 	        	RDEBUG("invalidNumber<0", invalidNumber );
       
   344 	        	// nothing to do
       
   345 	        	}
       
   346 				if(invalidNumber==EDeviceLockAutolockperiod)
       
   347 	        	{
       
   348 	        	RDEBUG("EDeviceLockAutolockperiod", invalidNumber );
       
   349 	        	newTitleText+=hbTrId("EDeviceLockAutolockperiod");
       
   350 	        	}
       
   351 	        if(invalidNumber==EDeviceLockMaxAutolockPeriod)
       
   352 	        	{
       
   353 	        	RDEBUG("EDeviceLockAutolockperiod", invalidNumber );
       
   354 	        	newTitleText+=hbTrId("EDeviceLockMaxAutolockPeriod");
       
   355 	        	}
       
   356 	        if(invalidNumber==EDeviceLockMinlength)
       
   357 	        	{
       
   358 	        	RDEBUG("EDeviceLockMinlength", invalidNumber );
       
   359 	        	newTitleText+=hbTrId("EDeviceLockMinlength");
       
   360 	        	}
       
   361 	        if(invalidNumber==EDeviceLockMaxlength)
       
   362 	        	{
       
   363 	        	RDEBUG("EDeviceLockMaxlength", invalidNumber );
       
   364 	        	newTitleText+=hbTrId("EDeviceLockMaxlength");
       
   365 	        	}
       
   366 	        if(invalidNumber==EDeviceLockRequireUpperAndLower)
       
   367 	        	{
       
   368 	        	RDEBUG("EDeviceLockRequireUpperAndLower", invalidNumber );
       
   369 	        	newTitleText+=hbTrId("EDeviceLockRequireUpperAndLower");
       
   370 	        	}
       
   371 	        if(invalidNumber==EDeviceLockRequireCharsAndNumbers)
       
   372 	        	{
       
   373 	        	RDEBUG("EDeviceLockMaxlength", invalidNumber );
       
   374 	        	newTitleText+=hbTrId("EDeviceLockMaxlength");
       
   375 	        	}
       
   376 	        if(invalidNumber==EDeviceLockAllowedMaxRepeatedChars)
       
   377 	        	{
       
   378 	        	RDEBUG("EDeviceLockAllowedMaxRepeatedChars", invalidNumber );
       
   379 	        	newTitleText+=hbTrId("EDeviceLockAllowedMaxRepeatedChars");
       
   380 	        	}
       
   381 	        if(invalidNumber==EDeviceLockHistoryBuffer)
       
   382 	        	{
       
   383 	        	RDEBUG("EDeviceLockHistoryBuffer", invalidNumber );
       
   384 	        	newTitleText+=hbTrId("EDeviceLockHistoryBuffer");
       
   385 	        	}
       
   386 	        if(invalidNumber==EDeviceLockPasscodeExpiration)
       
   387 	        	{
       
   388 	        	RDEBUG("EDeviceLockPasscodeExpiration", invalidNumber );
       
   389 	        	newTitleText+=hbTrId("EDeviceLockPasscodeExpiration");
       
   390 	        	}
       
   391 	        if(invalidNumber==EDeviceLockMinChangeTolerance)
       
   392 	        	{
       
   393 	        	RDEBUG("EDeviceLockMinChangeTolerance", invalidNumber );
       
   394 	        	newTitleText+=hbTrId("EDeviceLockMinChangeTolerance");
       
   395 	        	}
       
   396 	        if(invalidNumber==EDeviceLockMinChangeInterval)
       
   397 	        	{
       
   398 	        	RDEBUG("EDeviceLockMinChangeInterval", invalidNumber );
       
   399 	        	newTitleText+=hbTrId("EDeviceLockMinChangeInterval");
       
   400 	        	}
       
   401 	        if(invalidNumber==EDeviceLockDisallowSpecificStrings)
       
   402 	        	{
       
   403 	        	RDEBUG("EDeviceLockDisallowSpecificStrings", invalidNumber );
       
   404 	        	newTitleText+=hbTrId("EDeviceLockDisallowSpecificStrings");
       
   405 	        	}
       
   406 	        if(invalidNumber==EDeviceLockAllowedMaxAtempts)
       
   407 	        	{
       
   408 	        	RDEBUG("EDeviceLockAllowedMaxAtempts", invalidNumber );
       
   409 	        	newTitleText+=hbTrId("EDeviceLockAllowedMaxAtempts");
       
   410 	        	}
       
   411 	        if(invalidNumber==EDeviceLockConsecutiveNumbers)
       
   412 	        	{
       
   413 	        	RDEBUG("EDeviceLockConsecutiveNumbers", invalidNumber );
       
   414 	        	newTitleText+=hbTrId("EDeviceLockConsecutiveNumbers");
       
   415 	        	}
       
   416 	        if(invalidNumber==EDeviceLockMinSpecialCharacters)
       
   417 	        	{
       
   418 	        	RDEBUG("EDeviceLockMinSpecialCharacters", invalidNumber );
       
   419 	        	newTitleText+=hbTrId("EDeviceLockMinSpecialCharacters");
       
   420 	        	}
       
   421 	        if(invalidNumber==EDeviceLockSingleCharRepeatNotAllowed)
       
   422 	        	{
       
   423 	        	RDEBUG("EDeviceLockSingleCharRepeatNotAllowed", invalidNumber );
       
   424 	        	newTitleText+=hbTrId("EDeviceLockSingleCharRepeatNotAllowed");
       
   425 	        	}
       
   426 	        if(invalidNumber==EDevicelockConsecutiveCharsNotAllowed)
       
   427 	        	{
       
   428 	        	RDEBUG("EDevicelockConsecutiveCharsNotAllowed", invalidNumber );
       
   429 	        	newTitleText+=hbTrId("EDevicelockConsecutiveCharsNotAllowed");
       
   430 	        	}
       
   431 	        if(invalidNumber>=EDevicelockTotalPolicies)
       
   432 	        	{
       
   433 	        	RDEBUG("EDevicelockTotalPolicies", invalidNumber );
       
   434 	        	newTitleText+=hbTrId("EDevicelockTotalPolicies");
       
   435 	        	}
       
   436 	        if( !titleWidget )
       
   437 	        	{
       
   438 	        	RDEBUG("creating titleWidget", 0 );
       
   439 	        	titleWidget = new HbLabel(hbTrId("New lock code"));	// it will be changed later
       
   440           	setHeadingWidget(titleWidget);
       
   441           	}
       
   442           RDEBUG("setPlainText", 0 );
       
   443 	        titleWidget->setPlainText(newTitleText);
       
   444 	        
       
   445 	        if(invalidNumber<0)	// everything is ok
       
   446 	        	{
       
   447 	        	okAction->setEnabled(true);	// this might fail in the scenario: check this : invalid -> valid. This allows verif ?
       
   448 	        	okAction->setText(hbTrId("Ok"));
       
   449 	        	codeBottom->setEnabled(true);
       
   450 	        	}
       
   451 	        else
       
   452 	        	{
       
   453 	        	okAction->setEnabled(false);
       
   454 	        	codeBottom->setEnabled(false);
       
   455 	        	codeBottom->setText("");
       
   456 	        	okAction->setText(hbTrId("Ok"));
       
   457 	        	}
       
   458 	        // need to return because all objects are already created
       
   459    				return true;
       
   460 	    }
       
   461 	
       
   462     // Content
       
   463     SecUiNotificationContentWidget *content = new SecUiNotificationContentWidget();
       
   464     content->constructFromParameters(parameters);
       
   465     setContentWidget(content);
       
   466 
       
   467 		queryType = content->queryType;
       
   468 		queryDual = content->queryDual;
       
   469 		isEmergency = content->isEmergency;
       
   470     codeTop=NULL;
       
   471 		codeTop = content->codeTop;
       
   472     checkBox = content->checkbox;
       
   473     listWidget = content->listWidget;
       
   474 		codeBottom = content->codeBottom;
       
   475 		lMinLength = content->lMinLength;
       
   476 		lMaxLength = content->lMaxLength;
       
   477 		lEmergencySupported = content->lEmergencySupported;
       
   478 
       
   479     connect(content, SIGNAL(codeTopChanged(const QString &)), this, SLOT(handleCodeTopChanged(const QString &)));
       
   480     connect(content, SIGNAL(codeBottomChanged(const QString &)), this, SLOT(handleCodeBottomChanged(const QString &)));
       
   481     connect(content, SIGNAL(codeTopContentChanged()), this, SLOT(handleCodeTopContentChanged()));
       
   482     connect(content, SIGNAL(but1Changed()), this, SLOT(handlebut1Changed()));
       
   483     connect(content, SIGNAL(but2Changed()), this, SLOT(handlebut2Changed()));
       
   484     connect(content, SIGNAL(but3Changed()), this, SLOT(handlebut3Changed()));
       
   485 		RDEBUG("queryType", queryType);
       
   486     // Buttons
       
   487     if( (queryType & ESecUiTypeMaskLock))
       
   488     	{
       
   489     	// no need to create OK or Cancel
       
   490     	return true;
       
   491     	}
       
   492 
       
   493     okAction = new HbAction(hbTrId("Ok"));
       
   494     RDEBUG("created HbAction okAction", 1);
       
   495     okAction->setEnabled(false);	// initially the OK is disabled because codeTop is empty
       
   496     if((queryType & ESecUiBasicTypeMask) ==ESecUiBasicTypeCheck) {
       
   497         okAction->setEnabled(true);
       
   498         setHeadingWidget(0); // had to remove this no multiline
       
   499     }
       
   500     else if ((queryType & ESecUiBasicTypeMask) ==ESecUiBasicTypeCheckMulti){
       
   501         okAction->setEnabled(true);
       
   502     }
       
   503 
       
   504     // setAction(okAction, QDialogButtonBox::AcceptRole);	// it's supposed to use this, when deprecated
       
   505     // setPrimaryAction(okAction);
       
   506     addAction(okAction);
       
   507     disconnect(okAction, SIGNAL(triggered()), this, SLOT(close()));	// the close will be done in handleAccepted
       
   508     connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
       
   509     
       
   510     cancelAction = new HbAction(hbTrId("Cancel"));    // qtTrId("txt_common_button_cancel")
       
   511     addAction(cancelAction);
       
   512     disconnect(cancelAction, SIGNAL(triggered()), this, SLOT(close()));	// the close will be done in handleCancelled
       
   513     connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
       
   514     // setAction(cancelAction, QDialogButtonBox::RejectRole);		// it's supposed to use this, when deprecated
       
   515     // setSecondaryAction(cancelAction);
       
   516 
       
   517 		// this should had been set by Autolock, but just to be sure
       
   518     TInt ret = RProperty::Define(KPSUidSecurityUIs, KSecurityUIsDismissDialog,
       
   519             RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
       
   520             TSecurityPolicy(TSecurityPolicy::EAlwaysPass));
       
   521     RDEBUG("defined KSecurityUIsDismissDialog", ret);
       
   522     TInt aDismissDialog = -1;
       
   523     ret = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog );
       
   524     RDEBUG("ret", ret);
       
   525     RDEBUG("aDismissDialog", aDismissDialog);
       
   526     if(aDismissDialog==ESecurityUIsDismissDialogOn || aDismissDialog==ESecurityUIsDismissDialogProcessing)
       
   527     	{
       
   528     	RDebug::Printf( "potential error: %s %s (%u) aDismissDialog=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aDismissDialog );
       
   529     	}
       
   530 	
       
   531 		RDEBUG("check cancel", 0);
       
   532     if ((queryType & ESecUiCancelSupported)==ESecUiCancelSupported)
       
   533     	{
       
   534     		// nothing to do. Cancel is enabled by default
       
   535     	}
       
   536   	else
       
   537   		{
       
   538 				RDEBUG("disable Cancel", 1);
       
   539   			cancelAction->setEnabled(false);
       
   540   			cancelAction->setText("");
       
   541   			cancelAction->setVisible(false);
       
   542   		}
       
   543     
       
   544     return true;
       
   545 }
       
   546 
       
   547 // ----------------------------------------------------------------------------
       
   548 // SecUiNotificationDialog::sendResult()
       
   549 // ----------------------------------------------------------------------------
       
   550 //
       
   551 void SecUiNotificationDialog::sendResult(int accepted)
       
   552 {
       
   553 		RDEBUG("0", 0);
       
   554 		RDEBUG("mMyId", mMyId);
       
   555     QVariant acceptedValue(accepted);
       
   556 		RDEBUG("0", 0);
       
   557     mResultMap.insert(KResultAccepted, acceptedValue);
       
   558 		RDEBUG("0", 0);
       
   559 		RDEBUGQT("mResultMap", mResultMap);
       
   560 		RDEBUG("queryType", queryType);
       
   561 		if(!(queryType & ESecUiTypeMaskLock))
       
   562 			{	// the lock-icon should not reply
       
   563 			RDEBUG("emit deviceDialogData", 0);
       
   564     	emit deviceDialogData(mResultMap);
       
   565     	}
       
   566 		RDEBUG("1", 1);
       
   567 }
       
   568 
       
   569 // ----------------------------------------------------------------------------
       
   570 // SecUiNotificationDialog::handleAccepted()
       
   571 // ----------------------------------------------------------------------------
       
   572 //
       
   573 void SecUiNotificationDialog::handleAccepted()
       
   574 {
       
   575 		RDEBUG("0", 0);
       
   576 		// okAction
       
   577 		RDEBUG("mMyId", mMyId);
       
   578 		QString codeTopText="";
       
   579 
       
   580 		if( (queryType & ESecUiTypeMaskLock))
       
   581     	{
       
   582     	codeTopText = "Unlock-Request";
       
   583     	}
       
   584     else if( (queryType & ESecUiBasicTypeMask)==ESecUiBasicTypeCheck)
       
   585     	{
       
   586         codeTopText=(checkBox->isChecked() ?  "1":"0");
       
   587         mResultMap.insert(KCodeTopIndex,  codeTopText);
       
   588     	}
       
   589     else if( (queryType & ESecUiBasicTypeMask)==ESecUiBasicTypeCheckMulti)
       
   590     	{
       
   591         QItemSelectionModel *selectionModel = listWidget->selectionModel();
       
   592         QModelIndexList selectedItems = selectionModel->selectedIndexes();
       
   593         QModelIndex index;
       
   594         codeTopText="";
       
   595          foreach(index, selectedItems) { 
       
   596 		 		 codeTopText+=QString::number(index.row());
       
   597                 // could also use  if(index.row()!=selectedItems.count()-1) codeTopText+= "|";
       
   598                 codeTopText+= "|";
       
   599                 }
       
   600          mResultMap.insert(KCodeTopIndex,  codeTopText);
       
   601     	}
       
   602     else
       
   603         codeTopText = codeTop->text();
       
   604     // no need to check last time for codeBottom
       
   605    	RDEBUGQT("codeTopText", codeTopText);
       
   606     sendResult(KErrNone);
       
   607     RDEBUG("calling close()", 0);
       
   608     close();	// this is needed because Cancel doesn't automatically closes the dialog
       
   609 		RDEBUG("emitting deviceDialogClosed", 0);
       
   610 		emit deviceDialogClosed();
       
   611 }
       
   612 
       
   613 // ----------------------------------------------------------------------------
       
   614 // SecUiNotificationDialog::handleCancelled()
       
   615 // ----------------------------------------------------------------------------
       
   616 //
       
   617 void SecUiNotificationDialog::handleCancelled()
       
   618 {
       
   619 		RDEBUG("0", 0);
       
   620 		RDEBUG("mMyId", mMyId);
       
   621     sendResult(KErrCancel);
       
   622 		RDEBUG("callingclose()", 0);
       
   623     close();	// this is needed because Cancel doesn't automatically closes the dialog
       
   624 		RDEBUG("emitting deviceDialogClosed", 0);
       
   625 		emit deviceDialogClosed();
       
   626 }
       
   627 
       
   628 // ----------------------------------------------------------------------------
       
   629 // SecUiNotificationDialog::handleMemorySelectionChanged()
       
   630 // ----------------------------------------------------------------------------
       
   631 //
       
   632 void SecUiNotificationDialog::handleMemorySelectionChanged(const QString &text)
       
   633     {
       
   634 		RDEBUG("0", 0);
       
   635 		RDEBUG("mMyId", mMyId);
       
   636     RDEBUGQT("text", text);
       
   637     QVariant memorySelection(text);
       
   638     mResultMap.insert(KSelectedMemoryIndex, memorySelection);
       
   639     }
       
   640 
       
   641 void SecUiNotificationDialog::handleCodeTopContentChanged()
       
   642     {
       
   643 		RDEBUG("0", 0);
       
   644 		RDEBUG("mMyId", mMyId);
       
   645     	RDEBUGQT("codeTop->text()", codeTop->text());
       
   646     	handleCodeTopChanged(codeTop->text());
       
   647     }
       
   648 
       
   649 // ----------------------------------------------------------------------------
       
   650 // SecUiNotificationDialog::handleCodeTopChanged()
       
   651 // ----------------------------------------------------------------------------
       
   652 //
       
   653 void SecUiNotificationDialog::handleCodeTopChanged(const QString &text)
       
   654     {
       
   655 		RDEBUG("0", 0);
       
   656     	RDEBUGQT("text", text);
       
   657     	if(queryDual)
       
   658     		{
       
   659     		codeBottom->setText("");	// any change resets the verification.
       
   660 	    	if( (queryType & ESecUiMaskType) == 0x000004  )	// new codeLock
       
   661 	    		{	// ChangeSecCodeParamsL change RMobilePhone::ESecurityCodePhonePassword
       
   662 				    QVariant codeTopVar(text);
       
   663 				    mResultMap.insert(KCodeTopIndex, codeTopVar);
       
   664 						sendResult(KErrCompletion);	// send the current password back to the client for further TARM validation. This is done on any key-press, not in the OK
       
   665 	    		}
       
   666     		}
       
   667     	else if(text.length() < lMinLength )
       
   668     		{
       
   669     		RDEBUGQT("too short text", text);
       
   670     		okAction->setEnabled(false);
       
   671 				RDEBUG("lEmergencySupported", lEmergencySupported);
       
   672 				if( lEmergencySupported && text.length() > 2 )	// emergency numbers need at least 3 digits
       
   673 					{	// check whether it's a emergency number
       
   674 					QVariant codeTopVar(text);
       
   675   				mResultMap.insert(KCodeTopIndex, codeTopVar);
       
   676 					sendResult(KErrAbort);	// send the current password back to the client. Perhaps it's an emergency number and decides to Ok->Call
       
   677 					}
       
   678     		}
       
   679     	else if (text.length() >= lMinLength)
       
   680     		{
       
   681     		// might use a flag to avoid re-setting. But this complicates things if there's another initial verification
       
   682     		RDEBUGQT("long enough text", text);
       
   683     		okAction->setText(hbTrId("Ok"));
       
   684     		if(queryDual==0)	// only if Bottom is not used
       
   685     			okAction->setEnabled(true);
       
   686     		}
       
   687     QVariant codeTopVar(text);
       
   688     mResultMap.insert(KCodeTopIndex, codeTopVar);
       
   689     }
       
   690 // ----------------------------------------------------------------------------
       
   691 // SecUiNotificationDialog::handleCodeBottomChanged()
       
   692 // ----------------------------------------------------------------------------
       
   693 //
       
   694 void SecUiNotificationDialog::handleCodeBottomChanged(const QString &text)
       
   695     {
       
   696 		RDEBUG("0", 0);
       
   697     	RDEBUGQT("text", text);
       
   698     	RDEBUGQT("codeTop->text()", codeTop->text());
       
   699     	if(text.length() < lMinLength )
       
   700     		{
       
   701     		RDEBUGQT("too short text", text);
       
   702     		okAction->setEnabled(false);
       
   703     		}
       
   704     	else
       
   705     		{
       
   706     		// might use a flag to avoid re-setting. But it just complicates things.
       
   707     		RDEBUGQT("long enough text", text);
       
   708     		if(codeTop->text()==text)
       
   709     			{
       
   710     			// unless both codes match, don't allow OK. Note that the first field doesn't allow exit until the validations (i.e. NewLockCode) as succesfull
       
   711     			RDEBUGQT("codes match", text);
       
   712 	    		okAction->setEnabled(true);
       
   713 	    		}
       
   714 	    	else
       
   715 	    		{
       
   716     			RDEBUGQT("codes don't match", text);
       
   717 					okAction->setEnabled(false);
       
   718 	    		}
       
   719     		}
       
   720 		// verification is not sent
       
   721     }
       
   722 // ----------------------------------------------------------------------------
       
   723 // SecUiNotificationDialog::handlebut1Changed()
       
   724 // ----------------------------------------------------------------------------
       
   725 //
       
   726 void SecUiNotificationDialog::handlebut1Changed()
       
   727     {
       
   728 		RDEBUG("0", 0);
       
   729     codeTop->setText("1234");
       
   730     }
       
   731 // ----------------------------------------------------------------------------
       
   732 // SecUiNotificationDialog::handlebut2Changed()
       
   733 // ----------------------------------------------------------------------------
       
   734 //
       
   735 void SecUiNotificationDialog::handlebut2Changed()
       
   736     {
       
   737 		RDEBUG("0", 0);
       
   738     	QString codeTopText = codeTop->text();
       
   739     	RDEBUGQT("codeTopText", codeTopText);
       
   740     	codeTopText = codeTopText + "1" ;
       
   741     	RDEBUGQT("codeTopText+1", codeTopText);
       
   742     	codeTop->setText(codeTopText);
       
   743     	
       
   744     	      RDEBUG("editorInterface", 0);
       
   745       			HbEditorInterface editorInterface(codeTop);
       
   746       			RDEBUG("actions", 0);
       
   747       			QList<HbAction *> vkbList = editorInterface.actions();
       
   748       			RDEBUG("count", 0);
       
   749       			int count = vkbList.count();
       
   750       			RDEBUG("got count", count);
       
   751 		        for (int i = 0; i < count; i++)
       
   752 		        		{
       
   753 		        		RDEBUG("i", i);
       
   754 		            HbAction *action = static_cast<HbAction *>(vkbList[i]);
       
   755 		            RDEBUG("action", 0);
       
   756 		          	}
       
   757 		          	
       
   758 		        RDEBUG("okVKBAction", 0);
       
   759 		        okVKBAction = new HbAction(tr("Ok"));
       
   760 		        RDEBUG("addAction", 0);
       
   761 		        editorInterface.addAction(okVKBAction);
       
   762 		        RDEBUG("addAction", 1);
       
   763 		        connect(okVKBAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
       
   764 		        RDEBUG("connect", 1);
       
   765 
       
   766       			QList<HbAction *> vkbList2 = editorInterface.actions();
       
   767       			RDEBUG("count", 0);
       
   768       			int count2 = vkbList2.count();
       
   769       			RDEBUG("got count2", count2);
       
   770 		        for (int i = 0; i < count2; i++)
       
   771 		        		{
       
   772 		        		RDEBUG("i", i);
       
   773 		            HbAction *action2 = static_cast<HbAction *>(vkbList2[i]);
       
   774 		            RDEBUG("action2", 0);
       
   775 		          	}
       
   776     
       
   777     }
       
   778 // ----------------------------------------------------------------------------
       
   779 // SecUiNotificationDialog::handlebut3Changed()
       
   780 // ----------------------------------------------------------------------------
       
   781 //
       
   782 void SecUiNotificationDialog::handlebut3Changed()
       
   783     {
       
   784     	RDEBUG("0", 0);
       
   785     	QString codeTopText = codeTop->text();
       
   786     	RDEBUG("codeTopText", 0);
       
   787     	RDEBUGQT("codeTopText", codeTopText);
       
   788     	codeTopText = codeTopText + "5" ;
       
   789     	RDEBUGQT("codeTopText+5", codeTopText);
       
   790     	codeTop->setEchoMode(HbLineEdit::PasswordEchoOnEdit);
       
   791     	RDEBUGQT("codeTopText", codeTopText);
       
   792     	codeTop->setText(codeTopText);
       
   793     	RDEBUG("setFocus", 0);
       
   794     	codeTop->setFocus();
       
   795     	RDEBUG("1", 1);
       
   796     }
       
   797 
       
   798 // ----------------------------------------------------------------------------
       
   799 // SecUiNotificationDialog::saveFocusWidget(QWidget*,QWidget*)
       
   800 // ----------------------------------------------------------------------------
       
   801 //
       
   802 void SecUiNotificationDialog::saveFocusWidget(QWidget*,QWidget*)
       
   803 {
       
   804 		RDEBUG("0", 0);
       
   805 }
       
   806 
       
   807 // ----------------------------------------------------------------------------
       
   808 // SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
       
   809 // A way for Autolock to dismiss any possible PIN dialog
       
   810 // This doesn't dismiss the lockIcon because P&S is not connected
       
   811 // Note: if this changes itself, then it becomes recursive
       
   812 // ----------------------------------------------------------------------------
       
   813 //
       
   814 void SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
       
   815     {
       
   816 
       
   817     RDEBUG("0", 0);
       
   818 		RDEBUG("mMyId", mMyId);
       
   819     TInt aDismissDialog = ESecurityUIsDismissDialogUninitialized;
       
   820     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog );
       
   821     RDEBUG("err", err);
       
   822 		RDEBUG("aDismissDialog", aDismissDialog);
       
   823     if( aDismissDialog == ESecurityUIsDismissDialogOn )
       
   824     	{
       
   825     	if(subscriberKSecurityUIsDismissDialog)
       
   826     		{
       
   827     		RDEBUG("subscriberKSecurityUIsDismissDialog", 1);
       
   828     		}
       
   829     	else
       
   830     		{
       
   831     		RDEBUG("! subscriberKSecurityUIsDismissDialog", 0);
       
   832     		}
       
   833 
       
   834     	if(this)
       
   835     		{
       
   836     		RDEBUG("this", 1);
       
   837     		}
       
   838     	else
       
   839     		{
       
   840     		RDEBUG("! this", 0);
       
   841     		}
       
   842 
       
   843 
       
   844 			RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
       
   845 			disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   846 			// this doesn't really disconnect, because somehow the events are still queued. This is a QtMobility error
       
   847 			RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
       
   848 			
       
   849 			RDEBUG("not set KSecurityUIsDismissDialog", ESecurityUIsDismissDialogProcessing);
       
   850 			// can't set it because it does recursion
       
   851 			// err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsDismissDialog, ESecurityUIsDismissDialogProcessing );
       
   852 			RDEBUG("err", err);
       
   853 			// only if Cancel is allowed
       
   854 			if ((queryType & ESecUiCancelSupported)==ESecUiCancelSupported)
       
   855 				{
       
   856 				RDEBUG("sendResult(KErrCancel)", KErrCancel);	// another option is KErrDied
       
   857 				sendResult(KErrCancel);	// similar to     emit handleCancelled();
       
   858 				RDEBUG("calling close()", 0);
       
   859 				err = close();
       
   860 				RDEBUG("err", err);
       
   861 				RDEBUG("emitting deviceDialogClosed", 0);
       
   862 				emit deviceDialogClosed();
       
   863 				// RDEBUG("emit closeDeviceDialog", 0);
       
   864 				// this is old method    emit closeDeviceDialog(false);	// false means "not by client", although it's not really used
       
   865 				RDEBUG("all emited", 0);
       
   866 				}
       
   867 			RDEBUG("not set KSecurityUIsDismissDialog", ESecurityUIsDismissDialogDone);
       
   868 			// can't set it because it does recursion
       
   869 			// err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsDismissDialog, ESecurityUIsDismissDialogDone );	// clear after using it
       
   870 			RDEBUG("err", err);
       
   871 
       
   872 			RDEBUG("reconnect subscriberKSecurityUIsDismissDialog", 0);
       
   873 			connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   874 			RDEBUG("reconnected subscriberKSecurityUIsDismissDialog", 1);
       
   875     	}
       
   876     RDEBUG("1", 1);
       
   877 	}