securitydialogs/secuinotifications/secuinotificationdialogplugin/src/secuinotificationdialog.cpp
branchGCC_SURGE
changeset 40 604cd42065d1
parent 38 e0432375ea67
child 45 5d3e34b7618a
--- a/securitydialogs/secuinotifications/secuinotificationdialogplugin/src/secuinotificationdialog.cpp	Thu Jun 17 12:11:51 2010 +0100
+++ b/securitydialogs/secuinotifications/secuinotificationdialogplugin/src/secuinotificationdialog.cpp	Thu Jul 22 16:43:28 2010 +0100
@@ -15,6 +15,7 @@
 *
 */
 
+#include "secuinotificationdebug.h"
 #include "secuinotificationdialog.h"
 #include "secuinotificationdialogpluginkeys.h"
 #include "secuinotificationcontentwidget.h"
@@ -23,10 +24,21 @@
 #include <hbaction.h>
 #include <QDebug>
 #include <e32debug.h>
-#include <CPhCltEmergencyCall.h>
+#include <cphcltemergencycall.h>
 #include <SCPServerInterface.h>	// for TARM error codes while validating new lock code
 #include <QString>
 #include <QDialogButtonBox>
+#include <HbEditorInterface>
+#include <e32property.h>
+
+QTM_USE_NAMESPACE
+
+#include <qvaluespacesubscriber.h>
+#include <qvaluespacepublisher.h>
+#define ESecUiBasicTypeText    0x0000000
+#define ESecUiBasicTypeCheck   0x0010000
+#define ESecUiBasicTypeCheckMulti   0x0020000
+#define ESecUiBasicTypeMask    0x00F0000
 
 #define ESecUiCancelSupported  0x1000000
 #define ESecUiCancelNotSupported  0x0000000
@@ -50,6 +62,18 @@
 
 #define ESecUiTypeMaskLock			0x00F00000
 
+const TUid KPSUidSecurityUIs = { 0x100059b5 };
+const TUint32 KSecurityUIsDismissDialog  = 0x00000309;
+
+enum TSecurityUIsDismissDialogValues
+    {
+    ESecurityUIsDismissDialogUninitialized = 0,
+    ESecurityUIsDismissDialogOn,
+    ESecurityUIsDismissDialogProcessing,
+    ESecurityUIsDismissDialogDone,
+    ESecurityUIsDismissDialogLastValue
+    };
+
 // ----------------------------------------------------------------------------
 // SecUiNotificationDialog::SecUiNotificationDialog()
 // ----------------------------------------------------------------------------
@@ -57,7 +81,10 @@
 SecUiNotificationDialog::SecUiNotificationDialog(
         const QVariantMap &parameters) : HbDialog(), mLastError(KNoError)
 {
-		qDebug() << "SecUiNotificationDialog::SecUiNotificationDialog";
+		RDEBUG("0", 0);
+		TTime myTime;
+    myTime.HomeTime();
+		mMyId = I64LOW( myTime.Int64() );
     constructDialog(parameters);
 }
 
@@ -67,6 +94,7 @@
 //
 SecUiNotificationDialog::~SecUiNotificationDialog()
 {
+	RDEBUG("0", 0);
 }
 
 // ----------------------------------------------------------------------------
@@ -75,7 +103,7 @@
 //
 bool SecUiNotificationDialog::setDeviceDialogParameters(const QVariantMap &parameters)
 {
-		qDebug() << "SecUiNotificationDialog::setDeviceDialogParameters";
+	 RDEBUG("0", 0);
    return constructDialog(parameters);
 }
 
@@ -85,8 +113,8 @@
 //
 int SecUiNotificationDialog::deviceDialogError() const
 {
-		qDebug() << "SecUiNotificationDialog::deviceDialogError";
-		qDebug() << mLastError;
+		RDEBUG("mLastError", mLastError);
+		RDEBUG("mMyId", mMyId);
     return mLastError;
 }
 
@@ -97,14 +125,31 @@
 void SecUiNotificationDialog::closeDeviceDialog(bool byClient)
 {
     Q_UNUSED(byClient);
+		RDEBUG("mMyId", mMyId);
+		RDEBUG("calling close()", 0);
     close();
-		qDebug() << "SecUiNotificationDialog::closeDeviceDialog";
+		RDEBUG("mShowEventReceived", mShowEventReceived);
 
     // If show event has been received, close is signalled from hide event.
     // If not, hide event does not come and close is signalled from here.
     if (!mShowEventReceived) {
+    		RDEBUG("emitting deviceDialogClosed", 0);
         emit deviceDialogClosed();
+				if(1==0 && subscriberKSecurityUIsDismissDialog)
+					{
+						RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
+						disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
+						RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
+						if(1==1)
+							{
+							RDEBUG("deleting subscriberKSecurityUIsDismissDialog", 0);
+							delete subscriberKSecurityUIsDismissDialog;
+							subscriberKSecurityUIsDismissDialog = NULL;
+							RDEBUG("deleted subscriberKSecurityUIsDismissDialog", 1);
+							}
+				 }
     }
+    RDEBUG("0", 0);
 }
 
 // ----------------------------------------------------------------------------
@@ -122,9 +167,29 @@
 //
 void SecUiNotificationDialog::hideEvent(QHideEvent *event)
 {
-		qDebug() << "SecUiNotificationDialog::hideEvent";
+		RDEBUG("0", 0);
     HbDialog::hideEvent(event);
-    emit deviceDialogClosed();
+		RDEBUG("mMyId", mMyId);
+		RDEBUG("calling close()", 0);
+		close();
+		RDEBUG("emitting deviceDialogClosed", 0);
+		emit deviceDialogClosed();
+		RDEBUG("deviceDialogClosed", 1);
+		if(1==0 && subscriberKSecurityUIsDismissDialog)
+			{
+				RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
+				disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
+				RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
+				if(1==1)
+					{ 
+					RDEBUG("deleting subscriberKSecurityUIsDismissDialog", 0);
+					delete subscriberKSecurityUIsDismissDialog;
+					subscriberKSecurityUIsDismissDialog = NULL;
+					RDEBUG("deleted subscriberKSecurityUIsDismissDialog", 1);
+					}
+			}
+    // old method was   emit deviceDialogClosed();
+   RDEBUG("0", 0);
 }
 
 // ----------------------------------------------------------------------------
@@ -133,9 +198,46 @@
 //
 void SecUiNotificationDialog::showEvent(QShowEvent *event)
 {
-		qDebug() << "SecUiNotificationDialog::showEvent";
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
     HbDialog::showEvent(event);
+
+		if(!(queryType & ESecUiTypeMaskLock))
+			{	// not for the "lock icon"
+			RDEBUG("check default.1", 0);
+			if(codeTop!=NULL)
+            {
+            RDEBUG("check default.2", 0);
+            if(codeTop->text().length()>0)	// there's a default value. Verify it and (might) enable OK
+                {
+                RDEBUG("check default.3", 0);
+                handleCodeTopChanged(codeTop->text());
+                }
+            RDEBUG("setFocus", 0);
+      			codeTop->setFocus();	// this should open the VKB . Doesn't seem to work when it's done on the widget, so it's done here.
+
+            }	// codeTop!=NULL
+            
+			const TUint32 KSecurityUIsTestCode  = 0x00000307;
+			TInt value = 0;
+			TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsTestCode, value );
+			RDEBUG("KSecurityUIsTestCode err", err);
+			RDEBUG("faking value", value);
+			RDEBUG("mShowEventReceived", mShowEventReceived);
+			if(value>0 && mShowEventReceived==true)	// show happens 2 times. Dialog can be closed only the second.
+				{
+				QString myString = "";
+				myString += QString("%1").arg(value);
+				qDebug() << "SecUiNotificationDialog::faking myString=" << myString;
+		    codeTop->setText( myString );
+		    TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsTestCode, 0 );	// clear after using it
+				qDebug() << "SecUiNotificationDialog::calling handleAccepted=" << myString;
+		    emit handleAccepted();
+				// handleAccepted already   emit closeDeviceDialog(false);	// false means "not by client", although it's not really used
+				}
+			}
     mShowEventReceived = true;
+    RDEBUG("1", 1);
 }
 
 // ----------------------------------------------------------------------------
@@ -144,12 +246,31 @@
 //
 bool SecUiNotificationDialog::constructDialog(const QVariantMap &parameters)
     {
-		qDebug() << "SecUiNotificationDialog::constructDialog";
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
     setTimeout(HbPopup::NoTimeout);
     setDismissPolicy(HbPopup::NoDismiss);
     setModal(true);
+    mShowEventReceived = false;
+    subscriberKSecurityUIsDismissDialog = NULL;
+    titleWidget = NULL;
+		RDEBUG("subscriberKSecurityUIsDismissDialog NULL", 0);
+
+    subscriberKSecurityUIsDismissDialog = new QValueSpaceSubscriber("/KPSUidSecurityUIs/KSecurityUIsDismissDialog", this);
+    if(subscriberKSecurityUIsDismissDialog)
+    	{
+    	RDEBUG("subscriberKSecurityUIsDismissDialog created", 1);
+    	}
+    else
+    	{
+    	RDEBUG("subscriberKSecurityUIsDismissDialog not created", 0);
+    	}
+    connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
+		RDEBUG("subscriberKSecurityUIsDismissDialog", 1);
 
     // Title
+    // this is also done later in the widget
+    // For now, it only says "Security"
     if (parameters.contains(KDialogTitle)) {
         QString titleText = parameters.value(KDialogTitle).toString();
         QString titleAttempts = "";
@@ -162,22 +283,24 @@
     				titleAttempts = titleText.right(titleText.length()-titleText.indexOf('#')-1);
     				qDebug() << "SecUiNotificationDialog::titleAttempts=" << titleAttempts;
     				int nAttempts = titleAttempts.toInt();
-    				qDebug() << "SecUiNotificationDialog::nAttempts=" << nAttempts;
+    				RDEBUG("nAttempts", nAttempts);
     				titleText = titleText.left(titleText.indexOf('#'));
     				if(nAttempts>0)
     					titleText = titleText + " attempts=" + QString::number(nAttempts);
     				}
-        title = new HbLabel(titleText);
-        setHeadingWidget(title);
+    		titleText = "Security Query";	// this is the header, for any potential later error which needs to be displayed
+        // This is created only if needed (i.e. errors for NewLockCode)
+        // titleWidget = new HbLabel(titleText);
+        // setHeadingWidget(titleWidget);
     }
 
 	    if (parameters.contains(KEmergency)) {
-					qDebug() << "SecUiNotificationDialog::KEmergency";
+					RDEBUG("KEmergency", 1);
 	        QString emergencyText = parameters.value(KEmergency).toString();
 	        qDebug() << emergencyText;
 	        if(!emergencyText.compare("emergencyYes"))
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KEmergency emergencyYes";
+	        	RDEBUG("emergencyYes", 1);
 	        	isEmergency = 1;
 	        	okAction->setEnabled(true);
 	        	okAction->setText("Call");
@@ -185,121 +308,141 @@
 	        	}
 	        if(!emergencyText.compare("emergencyNo"))
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KEmergency emergencyNo";
+	        	RDEBUG("emergencyNo", 1);
 	        	isEmergency = 0;
 	        	okAction->setEnabled(false);	// 112 -> 1122 (=password) . This is handled by   < lMinLength 
 	        	okAction->setText("Ok");
     				return true;
 	        	}
 	    }
-	    
+	    // after TARM validation.
 	    if (parameters.contains(KInvalidNewLockCode)) {
-					qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode";
+					RDEBUG("KInvalidNewLockCode", 0);
 	        QString invalidText = parameters.value(KInvalidNewLockCode).toString();
 	        qDebug() << invalidText;
+	        QString newTitleText = "Lock Code";	// TODO take from the original one
 
-	        title->setPlainText("Lock Code");	// TODO take from the original one
 	        QString invalidStr = invalidText.right(invalidText.length()-invalidText.indexOf('#')-1);
 	        int invalidNumber = invalidStr.toInt();
-	        qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode invalidNumber" << invalidNumber;
+	        RDEBUG("invalidNumber", invalidNumber);
 	        if(invalidNumber<0)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode ???";
+	        	RDEBUG("invalidNumber<0", invalidNumber );
 	        	// nothing to do
 	        	}
-/*
-	        if(invalidNumber==EDeviceLockAutolockperiod)
+				if(invalidNumber==EDeviceLockAutolockperiod)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAutolockperiod";
-	        	title->setPlainText("EDeviceLockAutolockperiod");
+	        	RDEBUG("EDeviceLockAutolockperiod", invalidNumber );
+	        	newTitleText+="EDeviceLockAutolockperiod";
 	        	}
 	        if(invalidNumber==EDeviceLockMaxAutolockPeriod)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMaxAutolockPeriod";
-	        	title->setPlainText("EDeviceLockMaxAutolockPeriod");
+	        	RDEBUG("EDeviceLockAutolockperiod", invalidNumber );
+	        	newTitleText+="EDeviceLockMaxAutolockPeriod";
 	        	}
 	        if(invalidNumber==EDeviceLockMinlength)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinlength";
-	        	title->setPlainText("EDeviceLockMinlength");
+	        	RDEBUG("EDeviceLockMinlength", invalidNumber );
+	        	newTitleText+="EDeviceLockMinlength";
 	        	}
 	        if(invalidNumber==EDeviceLockMaxlength)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMaxlength";
-	        	title->setPlainText("EDeviceLockMaxlength");
+	        	RDEBUG("EDeviceLockMaxlength", invalidNumber );
+	        	newTitleText+="EDeviceLockMaxlength";
 	        	}
 	        if(invalidNumber==EDeviceLockRequireUpperAndLower)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockRequireUpperAndLower";
-	        	title->setPlainText("EDeviceLockRequireUpperAndLower");
+	        	RDEBUG("EDeviceLockRequireUpperAndLower", invalidNumber );
+	        	newTitleText+="EDeviceLockRequireUpperAndLower";
 	        	}
 	        if(invalidNumber==EDeviceLockRequireCharsAndNumbers)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockRequireCharsAndNumbers";
-	        	title->setPlainText("EDeviceLockMaxlength");
+	        	RDEBUG("EDeviceLockMaxlength", invalidNumber );
+	        	newTitleText+="EDeviceLockMaxlength";
 	        	}
 	        if(invalidNumber==EDeviceLockAllowedMaxRepeatedChars)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAllowedMaxRepeatedChars";
-	        	title->setPlainText("EDeviceLockAllowedMaxRepeatedChars");
+	        	RDEBUG("EDeviceLockAllowedMaxRepeatedChars", invalidNumber );
+	        	newTitleText+="EDeviceLockAllowedMaxRepeatedChars";
 	        	}
 	        if(invalidNumber==EDeviceLockHistoryBuffer)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockHistoryBuffer";
-	        	title->setPlainText("EDeviceLockHistoryBuffer");
+	        	RDEBUG("EDeviceLockHistoryBuffer", invalidNumber );
+	        	newTitleText+="EDeviceLockHistoryBuffer";
 	        	}
 	        if(invalidNumber==EDeviceLockPasscodeExpiration)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockPasscodeExpiration";
-	        	title->setPlainText("EDeviceLockPasscodeExpiration");
+	        	RDEBUG("EDeviceLockPasscodeExpiration", invalidNumber );
+	        	newTitleText+="EDeviceLockPasscodeExpiration";
 	        	}
 	        if(invalidNumber==EDeviceLockMinChangeTolerance)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinChangeTolerance";
-	        	title->setPlainText("EDeviceLockMinChangeTolerance");
+	        	RDEBUG("EDeviceLockMinChangeTolerance", invalidNumber );
+	        	newTitleText+="EDeviceLockMinChangeTolerance";
 	        	}
 	        if(invalidNumber==EDeviceLockMinChangeInterval)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinChangeInterval";
-	        	title->setPlainText("EDeviceLockMinChangeInterval");
+	        	RDEBUG("EDeviceLockMinChangeInterval", invalidNumber );
+	        	newTitleText+="EDeviceLockMinChangeInterval";
 	        	}
 	        if(invalidNumber==EDeviceLockDisallowSpecificStrings)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockDisallowSpecificStrings";
-	        	title->setPlainText("EDeviceLockDisallowSpecificStrings");
+	        	RDEBUG("EDeviceLockDisallowSpecificStrings", invalidNumber );
+	        	newTitleText+="EDeviceLockDisallowSpecificStrings";
 	        	}
 	        if(invalidNumber==EDeviceLockAllowedMaxAtempts)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockAllowedMaxAtempts";
-	        	title->setPlainText("EDeviceLockAllowedMaxAtempts");
+	        	RDEBUG("EDeviceLockAllowedMaxAtempts", invalidNumber );
+	        	newTitleText+="EDeviceLockAllowedMaxAtempts";
 	        	}
 	        if(invalidNumber==EDeviceLockConsecutiveNumbers)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockConsecutiveNumbers";
-	        	title->setPlainText("EDeviceLockConsecutiveNumbers");
+	        	RDEBUG("EDeviceLockConsecutiveNumbers", invalidNumber );
+	        	newTitleText+="EDeviceLockConsecutiveNumbers";
 	        	}
 	        if(invalidNumber==EDeviceLockMinSpecialCharacters)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockMinSpecialCharacters";
-	        	title->setPlainText("EDeviceLockMinSpecialCharacters");
+	        	RDEBUG("EDeviceLockMinSpecialCharacters", invalidNumber );
+	        	newTitleText+="EDeviceLockMinSpecialCharacters";
 	        	}
 	        if(invalidNumber==EDeviceLockSingleCharRepeatNotAllowed)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDeviceLockSingleCharRepeatNotAllowed";
-	        	title->setPlainText("EDeviceLockSingleCharRepeatNotAllowed");
+	        	RDEBUG("EDeviceLockSingleCharRepeatNotAllowed", invalidNumber );
+	        	newTitleText+="EDeviceLockSingleCharRepeatNotAllowed";
 	        	}
 	        if(invalidNumber==EDevicelockConsecutiveCharsNotAllowed)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDevicelockConsecutiveCharsNotAllowed";
-	        	title->setPlainText("EDevicelockConsecutiveCharsNotAllowed");
+	        	RDEBUG("EDevicelockConsecutiveCharsNotAllowed", invalidNumber );
+	        	newTitleText+="EDevicelockConsecutiveCharsNotAllowed";
 	        	}
 	        if(invalidNumber>=EDevicelockTotalPolicies)
 	        	{
-	        	qDebug() << "SecUiNotificationDialog::KInvalidNewLockCode EDevicelockTotalPolicies";
-	        	title->setPlainText("EDevicelockTotalPolicies");
+	        	RDEBUG("EDevicelockTotalPolicies", invalidNumber );
+	        	newTitleText+="EDevicelockTotalPolicies";
 	        	}
-	        	*/
-	        // always keep OK valid.
+	        if( !titleWidget )
+	        	{
+	        	RDEBUG("creating titleWidget", 0 );
+	        	titleWidget = new HbLabel("New lock code");	// it will be changed later
+          	setHeadingWidget(titleWidget);
+          	}
+          RDEBUG("setPlainText", 0 );
+	        titleWidget->setPlainText(newTitleText);
+	        
+	        if(invalidNumber<0)	// everything is ok
+	        	{
+	        	okAction->setEnabled(true);	// this might fail in the scenario: check this : invalid -> valid. This allows verif ?
+	        	okAction->setText("Ok");
+	        	codeBottom->setEnabled(true);
+	        	}
+	        else
+	        	{
+	        	okAction->setEnabled(false);
+	        	codeBottom->setEnabled(false);
+	        	codeBottom->setText("");
+	        	okAction->setText("Ok");
+	        	}
+	        // need to return because all objects are already created
    				return true;
 	    }
 	
@@ -311,7 +454,10 @@
 		queryType = content->queryType;
 		queryDual = content->queryDual;
 		isEmergency = content->isEmergency;
+    codeTop=NULL;
 		codeTop = content->codeTop;
+    checkBox = content->checkbox;
+    listWidget = content->listWidget;
 		codeBottom = content->codeBottom;
 		lMinLength = content->lMinLength;
 		lMaxLength = content->lMaxLength;
@@ -323,8 +469,7 @@
     connect(content, SIGNAL(but1Changed()), this, SLOT(handlebut1Changed()));
     connect(content, SIGNAL(but2Changed()), this, SLOT(handlebut2Changed()));
     connect(content, SIGNAL(but3Changed()), this, SLOT(handlebut3Changed()));
-		qDebug() << "SecUiNotificationDialog::queryType=";
-		qDebug() << queryType;
+		RDEBUG("queryType", queryType);
     // Buttons
     if( (queryType & ESecUiTypeMaskLock))
     	{
@@ -333,25 +478,54 @@
     	}
 
     okAction = new HbAction(tr("Ok"));
+    RDEBUG("created HbAction okAction", 1);
     okAction->setEnabled(false);	// initially the OK is disabled because codeTop is empty
+    if((queryType & ESecUiBasicTypeMask) ==ESecUiBasicTypeCheck) {
+        okAction->setEnabled(true);
+        setHeadingWidget(0); // had to remove this no multiline
+    }
+    else if ((queryType & ESecUiBasicTypeMask) ==ESecUiBasicTypeCheckMulti){
+        okAction->setEnabled(true);
+    }
+
     // setAction(okAction, QDialogButtonBox::AcceptRole);	// it's supposed to use this, when deprecated
-    setPrimaryAction(okAction);
+    // setPrimaryAction(okAction);
+    addAction(okAction);
+    disconnect(okAction, SIGNAL(triggered()), this, SLOT(close()));	// the close will be done in handleAccepted
     connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
     
     cancelAction = new HbAction(tr("Cancel"));    // qtTrId("txt_common_button_cancel")
+    addAction(cancelAction);
+    disconnect(cancelAction, SIGNAL(triggered()), this, SLOT(close()));	// the close will be done in handleCancelled
     connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
     // setAction(cancelAction, QDialogButtonBox::RejectRole);		// it's supposed to use this, when deprecated
-    setSecondaryAction(cancelAction);
+    // setSecondaryAction(cancelAction);
 
-		qDebug() << "SecUiNotificationDialog check Cancel";
+		// this should had been set by Autolock, but just to be sure
+    TInt ret = RProperty::Define(KPSUidSecurityUIs, KSecurityUIsDismissDialog,
+            RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
+            TSecurityPolicy(TSecurityPolicy::EAlwaysPass));
+    RDEBUG("defined KSecurityUIsDismissDialog", ret);
+    TInt aDismissDialog = -1;
+    ret = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog );
+    RDEBUG("ret", ret);
+    RDEBUG("aDismissDialog", aDismissDialog);
+    if(aDismissDialog==ESecurityUIsDismissDialogOn || aDismissDialog==ESecurityUIsDismissDialogProcessing)
+    	{
+    	RDebug::Printf( "potential error: %s %s (%u) aDismissDialog=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aDismissDialog );
+    	}
+	
+		RDEBUG("check cancel", 0);
     if ((queryType & ESecUiCancelSupported)==ESecUiCancelSupported)
     	{
     		// nothing to do. Cancel is enabled by default
     	}
   	else
   		{
-				qDebug() << "disable Cancel";
+				RDEBUG("disable Cancel", 1);
   			cancelAction->setEnabled(false);
+  			cancelAction->setText("");
+  			cancelAction->setVisible(false);
   		}
     
     return true;
@@ -363,14 +537,20 @@
 //
 void SecUiNotificationDialog::sendResult(int accepted)
 {
-		qDebug() << "SecUiNotificationDialog::sendResult 1.2";
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
     QVariant acceptedValue(accepted);
-		qDebug() << "SecUiNotificationDialog::sendResult 2";
+		RDEBUG("0", 0);
     mResultMap.insert(KResultAccepted, acceptedValue);
-		qDebug() << "SecUiNotificationDialog::sendResult 3";
+		RDEBUG("0", 0);
 		qDebug() << mResultMap;
-    emit deviceDialogData(mResultMap);
-		qDebug() << "SecUiNotificationDialog::sendResult end";
+		RDEBUG("queryType", queryType);
+		if(!(queryType & ESecUiTypeMaskLock))
+			{	// the lock-icon should not reply
+			RDEBUG("emit deviceDialogData", 0);
+    	emit deviceDialogData(mResultMap);
+    	}
+		RDEBUG("1", 1);
 }
 
 // ----------------------------------------------------------------------------
@@ -379,21 +559,42 @@
 //
 void SecUiNotificationDialog::handleAccepted()
 {
-		qDebug() << "SecUiNotificationDialog::handleAccepted";
+		RDEBUG("0", 0);
 		// okAction
-		QString codeTopText;
+		RDEBUG("mMyId", mMyId);
+		QString codeTopText="";
 
 		if( (queryType & ESecUiTypeMaskLock))
     	{
     	codeTopText = "Unlock-Request";
     	}
-    else
+    else if( (queryType & ESecUiBasicTypeMask)==ESecUiBasicTypeCheck)
+    	{
+        codeTopText=(checkBox->isChecked() ?  "1":"0");
+        mResultMap.insert(KCodeTopIndex,  codeTopText);
+    	}
+    else if( (queryType & ESecUiBasicTypeMask)==ESecUiBasicTypeCheckMulti)
     	{
-    	codeTopText = codeTop->text();
+        QItemSelectionModel *selectionModel = listWidget->selectionModel();
+        QModelIndexList selectedItems = selectionModel->selectedIndexes();
+        QModelIndex index;
+        codeTopText="";
+         foreach(index, selectedItems) { 
+		 		 codeTopText+=QString::number(index.row());
+                //could also use  if(index.row()!=selectedItems.count()-1) codeTopText+= "|";
+                codeTopText+= "|";
+                }
+         mResultMap.insert(KCodeTopIndex,  codeTopText);
     	}
-    // TODO check last time for codeBottom
+    else
+        codeTopText = codeTop->text();
+    // no need to check last time for codeBottom
    	qDebug() << "codeTopText=" << codeTopText;
     sendResult(KErrNone);
+    RDEBUG("calling close()", 0);
+    close();	// this is needed because Cancel doesn't automatically closes the dialog
+		RDEBUG("emitting deviceDialogClosed", 0);
+		emit deviceDialogClosed();
 }
 
 // ----------------------------------------------------------------------------
@@ -402,8 +603,13 @@
 //
 void SecUiNotificationDialog::handleCancelled()
 {
-		qDebug() << "SecUiNotificationDialog::handleCancelled";
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
     sendResult(KErrCancel);
+		RDEBUG("callingclose()", 0);
+    close();	// this is needed because Cancel doesn't automatically closes the dialog
+		RDEBUG("emitting deviceDialogClosed", 0);
+		emit deviceDialogClosed();
 }
 
 // ----------------------------------------------------------------------------
@@ -412,17 +618,17 @@
 //
 void SecUiNotificationDialog::handleMemorySelectionChanged(const QString &text)
     {
-    	qDebug() << "SecUiNotificationDialog::handleMemorySelectionChanged";
-    	qDebug() << text;
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
+    qDebug() << text;
     QVariant memorySelection(text);
     mResultMap.insert(KSelectedMemoryIndex, memorySelection);
-    //TODO: do we need emit here, or would it be better to send all data at the end?
-    //emit deviceDialogData(mResultMap);
     }
 
 void SecUiNotificationDialog::handleCodeTopContentChanged()
     {
-    	qDebug() << "SecUiNotificationDialog::handleCodeTopContentChanged";
+		RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
     	qDebug() << codeTop->text();
     	handleCodeTopChanged(codeTop->text());
     }
@@ -433,40 +639,40 @@
 //
 void SecUiNotificationDialog::handleCodeTopChanged(const QString &text)
     {
-    	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged";
+		RDEBUG("0", 0);
     	qDebug() << "SecUiNotificationDialog::handleCodeTopChanged=" << text ;
     	if(queryDual)
     		{
     		codeBottom->setText("");	// any change resets the verification.
     		}
-    	if( queryType == 0x1000004 )
+    	if( queryType == 0x1000004 )	// new codeLock
     		{	// ChangeSecCodeParamsL change RMobilePhone::ESecurityCodePhonePassword
-			    QVariant codeTop(text);
-			    mResultMap.insert(KCodeTopIndex, codeTop);
-					sendResult(KErrCompletion);	// send the current password back to the client for further TARM validation
+			    QVariant codeTopVar(text);
+			    mResultMap.insert(KCodeTopIndex, codeTopVar);
+					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
     		}
     	if(text.length() < lMinLength )
     		{
     		qDebug() << "SecUiNotificationDialog::handleCodeTopChanged too short:" << text ;
     		okAction->setEnabled(false);
-
+				RDEBUG("lEmergencySupported", lEmergencySupported);
 				if( lEmergencySupported && text.length() > 2 )	// emergency numbers need at least 3 digits
 					{	// check whether it's a emergency number
-					QVariant codeTop(text);
-  				mResultMap.insert(KCodeTopIndex, codeTop);
+					QVariant codeTopVar(text);
+  				mResultMap.insert(KCodeTopIndex, codeTopVar);
 					sendResult(KErrAbort);	// send the current password back to the client. Perhaps it's an emergency number and decides to Ok->Call
 					}
     		}
     	else if (text.length() >= lMinLength)
     		{
-    		// TODO might use a flag to avoid re-setting
+    		// might use a flag to avoid re-setting. But this complicates things if there's another initial verification
     		qDebug() << "SecUiNotificationDialog::handleCodeTopChanged long enough:" << text ;
     		okAction->setText("Ok");
     		if(queryDual==0)	// only if Bottom is not used
     			okAction->setEnabled(true);
     		}
-    QVariant codeTop(text);
-    mResultMap.insert(KCodeTopIndex, codeTop);
+    QVariant codeTopVar(text);
+    mResultMap.insert(KCodeTopIndex, codeTopVar);
     }
 // ----------------------------------------------------------------------------
 // SecUiNotificationDialog::handleCodeBottomChanged()
@@ -474,10 +680,9 @@
 //
 void SecUiNotificationDialog::handleCodeBottomChanged(const QString &text)
     {
-    	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged";
+		RDEBUG("0", 0);
     	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged" << text ;
     	qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged. codeTop=" << codeTop->text() ;
-    	// TODO compare 
     	if(text.length() < lMinLength )
     		{
     		qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged too short:" << text ;
@@ -485,10 +690,11 @@
     		}
     	else
     		{
-    		// TODO might use a flag to avoid re-setting
+    		// might use a flag to avoid re-setting. But it just complicates things.
     		qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged long enough:" << text ;
     		if(codeTop->text()==text)
     			{
+    			// 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
     			qDebug() << "SecUiNotificationDialog::handleCodeBottomChanged codes match:" << text ;
 	    		okAction->setEnabled(true);
 	    		}
@@ -506,8 +712,8 @@
 //
 void SecUiNotificationDialog::handlebut1Changed()
     {
-    	qDebug() << "SecUiNotificationDialog::handlebut1Changed";
-    	codeTop->setText("1234");
+		RDEBUG("0", 0);
+    codeTop->setText("1234");
     }
 // ----------------------------------------------------------------------------
 // SecUiNotificationDialog::handlebut2Changed()
@@ -515,7 +721,7 @@
 //
 void SecUiNotificationDialog::handlebut2Changed()
     {
-    	qDebug() << "SecUiNotificationDialog::handlebut2Changed";
+		RDEBUG("0", 0);
     	QString codeTopText = codeTop->text();
     	qDebug() << "codeTopText";
     	qDebug() << codeTopText;
@@ -523,6 +729,40 @@
     	qDebug() << "codeTopText+1";
     	qDebug() << codeTopText;
     	codeTop->setText(codeTopText);
+    	
+    	      RDEBUG("editorInterface", 0);
+      			HbEditorInterface editorInterface(codeTop);
+      			RDEBUG("actions", 0);
+      			QList<HbAction *> vkbList = editorInterface.actions();
+      			RDEBUG("count", 0);
+      			int count = vkbList.count();
+      			RDEBUG("got count", count);
+		        for (int i = 0; i < count; i++)
+		        		{
+		        		RDEBUG("i", i);
+		            HbAction *action = static_cast<HbAction *>(vkbList[i]);
+		            RDEBUG("action", 0);
+		          	}
+		          	
+		        RDEBUG("okVKBAction", 0);
+		        okVKBAction = new HbAction(tr("Ok"));
+		        RDEBUG("addAction", 0);
+		        editorInterface.addAction(okVKBAction);
+		        RDEBUG("addAction", 1);
+		        connect(okVKBAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
+		        RDEBUG("connect", 1);
+
+      			QList<HbAction *> vkbList2 = editorInterface.actions();
+      			RDEBUG("count", 0);
+      			int count2 = vkbList2.count();
+      			RDEBUG("got count2", count2);
+		        for (int i = 0; i < count2; i++)
+		        		{
+		        		RDEBUG("i", i);
+		            HbAction *action2 = static_cast<HbAction *>(vkbList2[i]);
+		            RDEBUG("action2", 0);
+		          	}
+    
     }
 // ----------------------------------------------------------------------------
 // SecUiNotificationDialog::handlebut3Changed()
@@ -547,5 +787,77 @@
 //
 void SecUiNotificationDialog::saveFocusWidget(QWidget*,QWidget*)
 {
-		qDebug() << "SecUiNotificationDialog::saveFocusWidget";
+		RDEBUG("0", 0);
 }
+
+// ----------------------------------------------------------------------------
+// SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
+// A way for Autolock to dismiss any possible PIN dialog
+// This doesn't dismiss the lockIcon because P&S is not connected
+// Note: if this changes itself, then it becomes recursive
+// ----------------------------------------------------------------------------
+//
+void SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
+    {
+
+    RDEBUG("0", 0);
+		RDEBUG("mMyId", mMyId);
+    TInt aDismissDialog = ESecurityUIsDismissDialogUninitialized;
+    TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog );
+    RDEBUG("err", err);
+		RDEBUG("aDismissDialog", aDismissDialog);
+    if( aDismissDialog == ESecurityUIsDismissDialogOn )
+    	{
+    	if(subscriberKSecurityUIsDismissDialog)
+    		{
+    		RDEBUG("subscriberKSecurityUIsDismissDialog", 1);
+    		}
+    	else
+    		{
+    		RDEBUG("! subscriberKSecurityUIsDismissDialog", 0);
+    		}
+
+    	if(this)
+    		{
+    		RDEBUG("this", 1);
+    		}
+    	else
+    		{
+    		RDEBUG("! this", 0);
+    		}
+
+
+			RDEBUG("disconnect subscriberKSecurityUIsDismissDialog", 0);
+			disconnect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
+			// this doesn't really disconnect, because somehow the events are still queued. This is a QtMobility error
+			RDEBUG("disconnected subscriberKSecurityUIsDismissDialog", 1);
+			
+			RDEBUG("not set KSecurityUIsDismissDialog", ESecurityUIsDismissDialogProcessing);
+			// can't set it because it does recursion
+			// err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsDismissDialog, ESecurityUIsDismissDialogProcessing );
+			RDEBUG("err", err);
+			// only if Cancel is allowed
+			if ((queryType & ESecUiCancelSupported)==ESecUiCancelSupported)
+				{
+				RDEBUG("sendResult(KErrCancel)", KErrCancel);	// another option is KErrDied
+				sendResult(KErrCancel);	// similar to     emit handleCancelled();
+				RDEBUG("calling close()", 0);
+				err = close();
+				RDEBUG("err", err);
+				RDEBUG("emitting deviceDialogClosed", 0);
+				emit deviceDialogClosed();
+				// RDEBUG("emit closeDeviceDialog", 0);
+				// this is old method    emit closeDeviceDialog(false);	// false means "not by client", although it's not really used
+				RDEBUG("all emited", 0);
+				}
+			RDEBUG("not set KSecurityUIsDismissDialog", ESecurityUIsDismissDialogDone);
+			// can't set it because it does recursion
+			// err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsDismissDialog, ESecurityUIsDismissDialogDone );	// clear after using it
+			RDEBUG("err", err);
+
+			RDEBUG("reconnect subscriberKSecurityUIsDismissDialog", 0);
+			connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
+			RDEBUG("reconnected subscriberKSecurityUIsDismissDialog", 1);
+    	}
+    RDEBUG("1", 1);
+	}