policymanagement/policyengine/policyengineui/src/PolicyEngineUi.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
     1 /*
     1 /*
     2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: Implementation of policymanagement components
    14 * Description:  This file contains the implementation of PolicyEngineUI
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "PolicyEngineUI.h"
    18 
    19 #include <hbpopup.h>
    19 // INCLUDE FILES
    20 #include <hbinputdialog.h>
    20 #include "PolicyEngineUi.h"
    21 #include <hbdocumentloader.h>
    21 #include "debug.h"
    22 #include <hbdialog.h>
    22 #include "policyengineui.hrh"
    23 #include <hblabel.h>
    23 #include <policyengineuidlgs.rsg>
    24 #include <hbaction.h>
    24 
    25 #include <hbnotificationdialog.h>
    25 #include <bautils.h>
    26 #include <hbmessagebox.h>
    26 #include <eikenv.h>
    27 #include <hbdevicenotificationdialog.h>
    27 #include <StringLoader.h>
    28 #include "Logger.h"
    28 #include <AknQueryDialog.h>
    29 
    29 #include <eikprogi.h>
    30 const int KMaxTries = 4;
    30 #include <aknnotewrappers.h>
    31 const int KMaxCodeLength = 4;
    31 #include <aknmessagequerydialog.h>
    32 
    32 #include <data_caging_path_literals.hrh>
    33 
    33 #include "SyncService.h"
    34 // -----------------------------------------------------------------------------
    34 
    35 // PolicyEngineUI::PolicyEngineUI()
    35 #include <implementationproxy.h>
    36 // -----------------------------------------------------------------------------
    36 
    37 PolicyEngineUI::PolicyEngineUI(const QVariantMap& parameters)
    37 
    38     {
    38 _LIT( KCUIResourceFileName, "PolicyEngineUIDlgs.rsc" );
    39     estbTrustCount = KMaxTries;
    39 const TUid KUidPolicyEngineUi = { 0x10207817 };
    40     DisplayNotificationDialog(parameters);
    40 const TUid KScreenOutputChannel = { 0x0000781F };
    41     }
    41 
    42 
    42 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers );
    43 
    43 
    44 // -----------------------------------------------------------------------------
    44 
    45 // PolicyEngineUI::~PolicyEngineUI()
    45 // ---------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    46 // CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
    47 PolicyEngineUI::~PolicyEngineUI()
    47 // ---------------------------------------------------------
    48     {
    48 //
    49 
    49 
    50     }
    50 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers )
    51 
    51 {
    52 
    52     MEikSrvNotifierBase2 *policyEngineNotifier = CPolicyEngineNotifier::NewL();
    53 // -----------------------------------------------------------------------------
    53     
    54 // PolicyEngineUI::DisplayNotificationDialog()
    54     CleanupStack::PushL( policyEngineNotifier );
    55 // Read the parameters sent from client
    55     aNotifiers->AppendL( policyEngineNotifier );
    56 // -----------------------------------------------------------------------------
    56     CleanupStack::Pop( policyEngineNotifier ); // serNotify
    57 void PolicyEngineUI::DisplayNotificationDialog(const QVariantMap& parameters)
    57 	RDEBUG("PolicyEngineUI notifier created!");
    58     {
    58 }
    59     LOGSTRING( "+ DisplayNotificationDialog +" );
    59 
    60     QVariantMap::const_iterator i = parameters.constBegin();
    60 
    61 
    61 
    62     while (i != parameters.constEnd())
    62 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    63     { 
       
    64     CArrayPtrFlat<MEikSrvNotifierBase2>* array =
       
    65     new CArrayPtrFlat<MEikSrvNotifierBase2>( 1 );
       
    66 
       
    67     if (array)
    63         {
    68         {
    64         if (i.key().toAscii() == "serverdisplayname")
    69         TRAPD( err, CreateNotifiersL( array ) );
       
    70         if (err != KErrNone)
    65             {
    71             {
    66             iServerName = i.value().toString();
    72             delete array;
    67             }
    73             array = NULL;
    68         else if (i.key().toAscii() == "fingerprint")
       
    69             {
       
    70             iFingerprint = i.value().toString();
       
    71             }
       
    72         ++i;
       
    73         }
       
    74     
       
    75     TBuf<50> server(iServerName.utf16());
       
    76     TBuf<10> buffer(iFingerprint.utf16());
       
    77 
       
    78     LOGSTRING2( "serverdisplayname %S", &server );
       
    79     LOGSTRING2( "fingerprint %S", &buffer );
       
    80 
       
    81     ShowInputDialog();
       
    82     LOGSTRING( "- DisplayNotificationDialog -" );
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // PolicyEngineUI::ShowInputDialog()
       
    88 // Show the accept control dialog
       
    89 // -----------------------------------------------------------------------------
       
    90 void PolicyEngineUI::ShowInputDialog()
       
    91     {
       
    92     LOGSTRING( "+ ShowInputDialog +" );
       
    93     HbDocumentLoader loader;
       
    94     bool ok = false;
       
    95     loader.load(":/xml/dialog.docml", &ok);
       
    96     if (!ok)
       
    97         {
       
    98         return;
       
    99         }
       
   100 
       
   101     HbDialog *dialog1 =
       
   102             qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   103 
       
   104     //set heading content
       
   105     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   106             "qtl_dialog_pri_heading"));
       
   107     QString heading(hbTrId("txt_device_update_title_security_information"));
       
   108     contentheading->setPlainText(heading);
       
   109 
       
   110     //set body content
       
   111     HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   112             "qtl_dialog_pri5"));
       
   113 
       
   114     QString body(
       
   115             (hbTrId("txt_device_update_info_1_server_wants_to_contro").arg(
       
   116                     iServerName)));
       
   117     contentbody->setTextWrapping(Hb::TextWordWrap);
       
   118     contentbody->setPlainText(body);
       
   119 
       
   120     HbAction *primaryAction = qobject_cast<HbAction *> (
       
   121             dialog1->actions().at(0));
       
   122     HbAction *secondaryAction = qobject_cast<HbAction *> (
       
   123             dialog1->actions().at(1));
       
   124 
       
   125     //set dialog properties
       
   126     dialog1->setTimeout(HbPopup::NoTimeout);
       
   127     dialog1->setDismissPolicy(HbPopup::NoDismiss);
       
   128 
       
   129     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   130             SLOT(onOKSelected()));
       
   131     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   132             SLOT(onCancelSelected()));
       
   133 
       
   134     if (dialog1)
       
   135         dialog1->show();
       
   136 
       
   137     LOGSTRING( "- ShowInputDialog -" );
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // PolicyEngineUI::onOKSelected()
       
   143 // Show the user input dialog once control is accepted
       
   144 // -----------------------------------------------------------------------------
       
   145 void PolicyEngineUI::onOKSelected()
       
   146     {
       
   147 
       
   148     LOGSTRING( "+ onOKSelected +" );
       
   149 
       
   150     HbDocumentLoader loader;
       
   151     bool ok = false;
       
   152     loader.load(":/xml/InputDialog.docml", &ok);
       
   153     if (!ok)
       
   154         {
       
   155         return;
       
   156         }
       
   157 
       
   158     mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   159 
       
   160     //set heading content
       
   161     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   162             "qtl_dialog_pri_heading"));
       
   163     QString heading(hbTrId("txt_device_update_title_security_information"));
       
   164     contentheading->setPlainText(heading);
       
   165 
       
   166     //set label
       
   167     HbLabel *contentlabel = qobject_cast<HbLabel *> (loader.findWidget(
       
   168             "HeadingLabel"));
       
   169     contentlabel->setTextWrapping(Hb::TextWordWrap);
       
   170     QString label(
       
   171                 (hbTrId("txt_device_update_info_enter_first_4_characters_of").arg(
       
   172                         iServerName)));
       
   173     contentlabel ->setPlainText(label);
       
   174 
       
   175     //set length for editline
       
   176     mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget("InputLine"));
       
   177     mContentEdit->setMaxLength(KMaxCodeLength);
       
   178 
       
   179     //set dialog properties
       
   180     mdialog->setTimeout(HbPopup::NoTimeout);
       
   181     mdialog->setDismissPolicy(HbPopup::NoDismiss);
       
   182     
       
   183     HbAction* primaryAction = (HbAction*) (mdialog->actions().at(0));
       
   184     HbAction *secondaryAction = (HbAction*) (mdialog->actions().at(1));
       
   185     primaryAction->setEnabled(false);
       
   186 
       
   187     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   188             SLOT(establishTrust()));
       
   189     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   190             SLOT(cancelTrust()));
       
   191     QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
       
   192             SLOT(codeTextChanged()));
       
   193 
       
   194     if (mdialog)
       
   195         mdialog->show();
       
   196 
       
   197     LOGSTRING( "- onOKSelected -" );
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // PolicyEngineUI::onCancelSelected()
       
   203 // -----------------------------------------------------------------------------
       
   204 void PolicyEngineUI::onCancelSelected()
       
   205     {
       
   206     LOGSTRING( "+ onCancelSelected +" );
       
   207 
       
   208     QVariantMap result;
       
   209 
       
   210     result.insert("keyResponse", -1);
       
   211     emit
       
   212     deviceDialogData(result);
       
   213 
       
   214     emit
       
   215     deviceDialogClosed();
       
   216 
       
   217     LOGSTRING( "- onCancelSelected -" );
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // PolicyEngineUI::onTrustCreation()
       
   223 // -----------------------------------------------------------------------------
       
   224 void PolicyEngineUI::onTrustCreation()
       
   225     {
       
   226     LOGSTRING( "+ onTrustCreation +" );
       
   227     QVariantMap result;
       
   228 
       
   229     result.insert("keyResponse", 0);
       
   230     emit
       
   231     deviceDialogData(result);
       
   232 
       
   233     emit
       
   234     deviceDialogClosed();
       
   235 
       
   236     LOGSTRING( "- onTrustCreation -" );
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // PolicyEngineUI::establishTrust()
       
   242 // -----------------------------------------------------------------------------
       
   243 void PolicyEngineUI::establishTrust()
       
   244     {
       
   245     LOGSTRING( "+ establishTrust +" );
       
   246     bool retVal; // return value from code verification API.
       
   247     estbTrustCount--;
       
   248     retVal = verifyFingerPrint();
       
   249 
       
   250     if (retVal)
       
   251         {
       
   252         LOGSTRING( "Trust Created" );
       
   253         //Reset the counter.
       
   254         estbTrustCount = 0;
       
   255         onTrustCreation();
       
   256 
       
   257         }
       
   258     else
       
   259         {
       
   260         //check the number of tries.
       
   261         if (estbTrustCount == 0)
       
   262             {
       
   263             //Access denied.
       
   264             LOGSTRING( "Access Denied" );
       
   265             HbMessageBox *msgBox = new HbMessageBox();
       
   266             msgBox->setHeadingWidget(new HbLabel(hbTrId(
       
   267                     "txt_device_update_title_security_information")));
       
   268 
       
   269             msgBox->setText(hbTrId(
       
   270                     "txt_device_update_info_security_info_access_denied"));
       
   271             msgBox->setTimeout(HbDialog::NoTimeout);
       
   272             msgBox->setDismissPolicy(HbDialog::NoDismiss);
       
   273 
       
   274             HbAction *action = (HbAction*) (msgBox->actions().at(0));
       
   275             QObject::connect(action, SIGNAL(triggered()), this,
       
   276                     SLOT(onCancelSelected()));
       
   277 
       
   278             msgBox->show();
       
   279             }
       
   280         else
       
   281             {
       
   282             LOGSTRING2( "tries left %i", estbTrustCount );
       
   283             //Code didnot match.
       
   284             HbDocumentLoader loader;
       
   285             bool ok = false;
       
   286             loader.load(":/xml/InputDialog.docml", &ok);
       
   287             if (!ok)
       
   288                 {
       
   289                 return;
       
   290                 }
       
   291 
       
   292             mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   293 
       
   294             //set heading content
       
   295             HbLabel *contentheading = qobject_cast<HbLabel *> (
       
   296                     loader.findWidget("qtl_dialog_pri_heading"));
       
   297             contentheading->setTextWrapping(Hb::TextWordWrap);
       
   298             QString heading(hbTrId(
       
   299                     "txt_device_update_title_security_information"));
       
   300             contentheading->setPlainText(heading);
       
   301 
       
   302             //set label
       
   303             HbLabel *contentlabel = qobject_cast<HbLabel *> (
       
   304                     loader.findWidget("HeadingLabel"));
       
   305             QString
       
   306                     label(
       
   307                             (hbTrId(
       
   308                                     "txt_device_update_info_security_information_did_no").arg(
       
   309                                     estbTrustCount)));
       
   310 
       
   311             contentlabel->setTextWrapping(Hb::TextWordWrap);
       
   312             contentlabel->setPlainText(label);
       
   313 
       
   314             mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget(
       
   315                     "InputLine"));
       
   316             mContentEdit->setMaxLength(KMaxCodeLength);
       
   317 
       
   318             mdialog->setTimeout(HbPopup::NoTimeout);
       
   319             mdialog->setDismissPolicy(HbPopup::NoDismiss);
       
   320 
       
   321             HbAction* primaryAction = qobject_cast<HbAction*> (
       
   322                     mdialog->actions().at(0));
       
   323             HbAction *secondaryAction = qobject_cast<HbAction*> (
       
   324                     mdialog->actions().at(1));
       
   325             primaryAction->setEnabled(false);
       
   326 
       
   327             QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   328                     SLOT(establishTrust()));
       
   329             QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   330                     SLOT(cancelTrust()));
       
   331             QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
       
   332                     SLOT(codeTextChanged()));
       
   333 
       
   334             if (mdialog)
       
   335                 mdialog->show();
       
   336             }
    74             }
   337         }
    75         }
   338     LOGSTRING( "- establishTrust -" );
    76     return array;
   339     }
    77     }
   340 
    78 
   341 
    79 const TImplementationProxy ImplementationTable[] = { {{0x10207817},(TProxyNewLPtr)NotifierArray} };
   342 // -----------------------------------------------------------------------------
    80 
   343 // PolicyEngineUI::cancelTrust()
    81 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   344 // -----------------------------------------------------------------------------
    82 	{
   345 void PolicyEngineUI::cancelTrust()
    83 	RDEBUG("PolicyEngineUI notifier detected!");
       
    84 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy) ;
       
    85 	return ImplementationTable;
       
    86 	}
       
    87 
       
    88 
       
    89 
       
    90 CPolicyEngineNotifier::CPolicyEngineNotifier()
       
    91 	{
       
    92 	}
       
    93 
       
    94 
       
    95 CPolicyEngineNotifier::~CPolicyEngineNotifier()
       
    96 	{
       
    97 	//delete and close policy engine ui
       
    98 	delete iPolicyEngineUi;	
       
    99 	}
       
   100 
       
   101 
       
   102 CPolicyEngineNotifier* CPolicyEngineNotifier::NewL()
       
   103 	{
       
   104 	CPolicyEngineNotifier* self = new (ELeave) CPolicyEngineNotifier();
       
   105 	
       
   106 	CleanupStack::PushL( self);
       
   107 	self->ConstructL();	
       
   108 	CleanupStack::Pop();
       
   109 	
       
   110 	return self;
       
   111 	}
       
   112 
       
   113 void CPolicyEngineNotifier::ConstructL()
       
   114 	{
       
   115 	}
       
   116 		
       
   117 
       
   118 void CPolicyEngineNotifier::Release()
       
   119 	{
       
   120 	delete this;	
       
   121 	}
       
   122 
       
   123 
       
   124 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::RegisterL()
       
   125 	{
       
   126 	//Registration info
       
   127     iInfo.iUid = KUidPolicyEngineUi;
       
   128     iInfo.iPriority = ENotifierPriorityHigh;
       
   129 	iInfo.iChannel = KScreenOutputChannel;	
       
   130 	
       
   131 	return iInfo;
       
   132 	}
       
   133 
       
   134 
       
   135 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::Info() const
       
   136 	{
       
   137 	//Registration info
       
   138 	return iInfo;
       
   139 	}
       
   140 
       
   141 
       
   142 TPtrC8 CPolicyEngineNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   143 	{
       
   144 	return KNullDesC8().Ptr();
       
   145 	}
       
   146 
       
   147 
       
   148 void CPolicyEngineNotifier::Complete( TUserResponse aResponse)
       
   149 	{
       
   150 	RDEBUG("CPolicyEngineNotifier::Complete");
       
   151 
       
   152 	//Write return value to message and compeltes it
       
   153 	if ( aResponse == EUserAccept )
       
   154 		{
       
   155 		iMessage.Write( iReplySlot, KUserAcceptMark, 0);	
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		iMessage.Write( iReplySlot, KUserDenyMark, 0);	
       
   160 		}
       
   161 	
       
   162     iManager->CancelNotifier( iInfo.iUid );   // Notify framework we've done
       
   163 	iMessage.Complete( KErrNone);
       
   164 	}
       
   165 
       
   166 
       
   167 void CPolicyEngineNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   168 	{
       
   169 	RDEBUG("CPolicyEngineNotifier::StartL!");
       
   170 
       
   171 	TInt index = aBuffer.Locate( KDelimeterChar);
       
   172 	
       
   173 	if ( index != KErrNotFound && !iPolicyEngineUi)
       
   174 		{	
       
   175 		//decode name and fingerprint from message
       
   176 		TPtrC8 name = aBuffer.Left( index);
       
   177 		TPtrC8 fingerPrint = aBuffer.Mid( index + 1);
       
   178 
       
   179 		iReplySlot = aReplySlot;
       
   180 		iMessage = aMessage;
       
   181 
       
   182 		//Show policy engine ui dialogs
       
   183 		iPolicyEngineUi = CPolicyEngineUi::NewL();
       
   184 		iPolicyEngineUi->ActivateL( name, fingerPrint, this);
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		Complete( EUserDeny);
       
   189 		}
       
   190 	}
       
   191 
       
   192 
       
   193 void CPolicyEngineNotifier::Cancel()
       
   194 	{
       
   195 	RDEBUG("CPolicyEngineNotifier::Cancel!");
       
   196 
       
   197 	//Delete policy engine ui
       
   198 	delete iPolicyEngineUi;
       
   199 	iPolicyEngineUi = 0;
       
   200 	}
       
   201 
       
   202 
       
   203 TPtrC8 CPolicyEngineNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   204 	{
       
   205 	return KNullDesC8().Ptr();
       
   206 	}
       
   207 
       
   208 CPolicyEngineUi::CPolicyEngineUi()
       
   209 	: CActive( EPriorityStandard)
       
   210     {  
       
   211     }
       
   212 
       
   213 void CPolicyEngineUi::ConstructL()
   346     {
   214     {
   347     LOGSTRING( "+ cancelTrust +" );
   215 	RDEBUG("CPolicyEngineUi::ConstructL!");
   348     //Reset the counter.
   216 
   349     estbTrustCount = 0;
   217     //get pointer to CEikonEnv
   350 
   218 	iCoeEnv = CEikonEnv::Static();    
   351     QVariantMap result;
   219     
   352     result.insert("keyResponse", -1);
   220     if ( !iCoeEnv )
   353     emit
   221     	{
   354     deviceDialogData(result);
   222 		RDEBUG("Policy engine ui: CoeEnv not found!");
   355 
   223         User::Leave( KErrGeneral );        
   356     emit
   224     	}
   357     deviceDialogClosed();
   225 
   358     LOGSTRING( "- cancelTrust -" );
   226 	//Open resource file
   359     }
   227     TFileName fileName;
   360 
   228     fileName.Zero();
   361 
   229 
   362 // -----------------------------------------------------------------------------
   230     TFileName drivePath;
   363 // PolicyEngineUI::setDeviceDialogParameters()
   231     Dll::FileName( drivePath );
   364 // -----------------------------------------------------------------------------
   232 
   365 bool PolicyEngineUI::setDeviceDialogParameters(const QVariantMap &parameters)
   233     fileName.Append( TParsePtrC( drivePath ).Drive() );
       
   234     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   235     fileName.Append( KCUIResourceFileName );   
       
   236     
       
   237     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   238 
       
   239 	//handle to resource file
       
   240     iResourceFileOffset = iCoeEnv->AddResourceFileL( fileName );
       
   241 
       
   242 	RDEBUG("Policy engine ui resources loaded!");
       
   243  	}
       
   244 
       
   245 CPolicyEngineUi* CPolicyEngineUi::NewL()
       
   246 	{
       
   247     CPolicyEngineUi* self = new ( ELeave ) CPolicyEngineUi();
       
   248     CleanupStack::PushL( self );
       
   249     self->ConstructL();
       
   250     CleanupStack::Pop( self );
       
   251     return self; 
       
   252 	}
       
   253 
       
   254 
       
   255 CPolicyEngineUi::~CPolicyEngineUi()
       
   256 	{
       
   257 	RDEBUG("CPolicyEngineUi::~CPolicyEngineUi()");
       
   258 
       
   259     // Close non-modal dialogs
       
   260     if( iResourceFileOffset )
       
   261     	{
       
   262         iCoeEnv->DeleteResourceFile( iResourceFileOffset );
       
   263     	}
       
   264 	
       
   265 	delete iCorporate;
       
   266 	delete iRandomPart;
       
   267 	}
       
   268 
       
   269 
       
   270 void CPolicyEngineUi::ActivateL( const TDesC8& aCorporate, const TDesC8& aRandomPart, CPolicyEngineNotifier* aNotifier)
       
   271 	{
       
   272 	RDEBUG("CPolicyEngineUi::ActivateL");
       
   273 
       
   274 	//reference to notifier (for message completion)
       
   275 	iNotifier = aNotifier;
       
   276 	
       
   277 	//allocate new space for parameters and save them
       
   278 	delete iCorporate;
       
   279 	iCorporate = NULL;
       
   280 	delete iRandomPart;
       
   281 	iRandomPart = NULL;
       
   282 	iCorporate = HBufC::NewL( aCorporate.Length());
       
   283 	iRandomPart = HBufC::NewL( aRandomPart.Length());
       
   284 
       
   285 	iCorporate->Des().Copy( aCorporate);
       
   286 	iRandomPart->Des().Copy( aRandomPart);	
       
   287 	
       
   288 	//add active object to active scheduler and set object active
       
   289 	CActiveScheduler::Add( this);
       
   290 	SetActive();
       
   291 	
       
   292 	//complete request....
       
   293 	TRequestStatus * status = &iStatus;
       
   294 	User::RequestComplete( status, KErrNone);	
       
   295 	}
       
   296 
       
   297 
       
   298 
       
   299 void CPolicyEngineUi::RunL()
       
   300 	{
       
   301 	RDEBUG("CPolicyEngineUi::RunL()");
       
   302 	
       
   303 	//in state ERemove user has already accepted query
       
   304 	if ( ERemove == iState )
       
   305 		{
       
   306 		//show info, remove from scheduler
       
   307 		ShowDialogL( ERemove);
       
   308 		Deque();
       
   309 		iNotifier->Complete( EUserAccept);
       
   310 		return;		
       
   311 		}
       
   312 
       
   313 	if ( EDenied == iState )
       
   314 		{
       
   315 		//show info, remove from scheduler
       
   316 		ShowDialogL( EDenied);
       
   317 		Deque();
       
   318 		iNotifier->Complete( EUserDeny);
       
   319 		return;		
       
   320 		}
       
   321 
       
   322 	//Control dialog
       
   323 	if ( EUserAccept == ShowDialogL( (TDialog) iState))
       
   324 		{
       
   325 		//if user cancel dialog, show deny-dialog and return
       
   326 		iState = iState + 1;
       
   327 		}
       
   328 	else
       
   329 		{
       
   330 		//user press cancel -> state = EDenied
       
   331 		iState = EDenied;
       
   332 		}
       
   333 	
       
   334 	//set active and complete message
       
   335 	SetActive();
       
   336 	TRequestStatus * status = &iStatus;
       
   337 	User::RequestComplete( status, KErrNone);
       
   338 	}
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 // CPolicyEngineUi::RunError
       
   342 // ----------------------------------------------------------------------------
       
   343 TInt CPolicyEngineUi::RunError ( TInt /*aError*/ )
   366     {
   344     {
   367 	Q_UNUSED(parameters);
   345        return KErrNone;
   368     LOGSTRING( "+ setDeviceDialogParameters +" );
   346     }	
   369     return true;
   347 
   370     }
   348 void CPolicyEngineUi::DoCancel()
   371 
   349 	{
   372 
   350 	}
   373 // -----------------------------------------------------------------------------
   351 
   374 // PolicyEngineUI::deviceDialogError()
   352 
   375 // Get error
   353 
   376 // -----------------------------------------------------------------------------
   354 CPolicyEngineUi::TDlgResp CPolicyEngineUi::ShowConfirmationQueryL( 
   377 int PolicyEngineUI::deviceDialogError() const
   355 	const TDesC& aText, const TBool& aWithCancel)
   378     {
   356 	{
   379     LOGSTRING( "+ deviceDialogError +" );
   357 	//create dialog
   380     return 0;
   358     CAknQueryDialog* note = 
   381     }
   359         CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
   382 
   360 				
   383 
   361 	//select correct text resource 					 
   384 // -----------------------------------------------------------------------------
   362 	TInt resource = R_POLICYENGINEUI_CONFIRMATION_QUERY;
   385 // PolicyEngineUI::PolicyEngineUI()
   363 	
   386 // Close device dialog
   364 	if ( !aWithCancel )
   387 // -----------------------------------------------------------------------------
   365 		{
   388 void PolicyEngineUI::closeDeviceDialog(bool byClient)
   366 		resource = R_POLICYENGINEUI_CONFIRMATION;
   389     {
   367 		}			   
   390 	Q_UNUSED(byClient);
   368 						
   391     LOGSTRING( "+ closeDeviceDialog +" );
   369 	//execute dialog, dialog contains self destruction			 
   392     close();
   370     TInt response = note->ExecuteLD( resource, aText );
   393     }
   371     
   394 
   372 	if ( response )
   395 
   373 		{
   396 // -----------------------------------------------------------------------------
   374 		return EOkResp;
   397 // PolicyEngineUI::PolicyEngineUI()
   375 		}
   398 // Return display widget
   376 	
   399 // -----------------------------------------------------------------------------
   377 	return ECancelResp;
   400 HbDialog *PolicyEngineUI::deviceDialogWidget() const
   378 	}
   401     {
   379 
   402     LOGSTRING( "+ deviceDialogWidget +" );
   380 
   403     return const_cast<PolicyEngineUI*> (this);
   381 CPolicyEngineUi::TDlgResp CPolicyEngineUi::DataQueryL( const TDesC& aText, TDes& aInput )
   404     }
   382 	{
   405 
   383 
   406 
   384 	//Create dialog with reference to input descriptor
   407 // -----------------------------------------------------------------------------
   385 	CAknTextQueryDialog* dlg = 
   408 // PolicyEngineUI::PolicyEngineUI()
   386 		CAknTextQueryDialog::NewL( aInput, CAknQueryDialog::ENoTone);
   409 // Verify the user entered code
   387 
   410 // -----------------------------------------------------------------------------
   388 	//set prompt
   411 bool PolicyEngineUI::verifyFingerPrint()
   389 	CleanupStack::PushL( dlg);
   412     {
   390 	dlg->SetPromptL( aText);
   413     LOGSTRING( "+ verifyFingerPrint +" );
   391 	CleanupStack::Pop();
   414 
   392 	
   415     QString enteredCode = mContentEdit->text();
   393 	//execute dialog, dialog contains self destruction			 
   416     TBuf<10> buffer(enteredCode.utf16());
   394 	TInt response = dlg->ExecuteLD( R_POLICYENGINEUI_DATA_QUERY);
   417 
   395 	
   418     LOGSTRING2( "User entered code %i", &buffer);
   396 	if ( response )
   419     LOGSTRING2( "User entered code %S", &buffer);
   397 		{
   420 
   398 		return EOkResp;
   421     if (enteredCode.compare(iFingerprint, Qt::CaseInsensitive) == 0)
   399 		}
   422     {
   400 	
   423         LOGSTRING( "+ fingerprint MATCH !!!! +" );
   401 	return ECancelResp;
   424         return true;
   402 	}
   425     }
   403 
   426     else
   404 
   427     {
   405 TInt CPolicyEngineUi::ShowDialogL( const TDialog& aDialog)
   428         LOGSTRING( "+  fingerprint DOESNOT MATCH  +" );
   406 	{
   429         return false;
   407 	TInt response = EUserDeny;
   430     }
   408 
   431     }
   409 	//select correct dialog
   432 
   410 	switch ( aDialog)
   433 
   411 		{
   434 // -----------------------------------------------------------------------------
   412 		case EControl : 
   435 // PolicyEngineUI::codeTextChanged()
   413 			{
   436 // checks the entered text length and enables the OK option accordingly.
   414 			response = ShowPossessionMessageQueryL();
   437 // -----------------------------------------------------------------------------
   415 			break;
   438 void PolicyEngineUI::codeTextChanged()
   416 			}
   439     {
   417 		case ERemove:
   440     QString str = mContentEdit->text();
   418 			{
   441 
   419 			//load resource
   442     if (str.length() >= KMaxCodeLength)
   420 		    HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_TRUST_ESTABLISHED );
   443         mdialog->actions().at(0)->setEnabled(true);
   421 			
   444     else
   422 			TInt length1 = displayString->Length();
   445         mdialog->actions().at(0)->setEnabled(false);
   423 			HBufC16* trustString = HBufC16::NewLC ( length1  );
   446     }
   424 			TPtr bufPtr = trustString -> Des();
       
   425 			bufPtr.Append (*displayString);
       
   426 			// Hide background connecting note
       
   427 			CSyncService *syncService =
       
   428                             CSyncService::NewL(NULL, KDevManServiceStart);
       
   429                     if (syncService)
       
   430                         {
       
   431                         syncService->EnableProgressNoteL(EFalse);
       
   432                         }
       
   433 
       
   434                     delete syncService;
       
   435 			
       
   436 			response = ShowConfirmationQueryL( *trustString, EFalse);
       
   437 			CleanupStack::PopAndDestroy();
       
   438 			CleanupStack::PopAndDestroy();
       
   439 			
       
   440 			break;
       
   441 			}
       
   442 		case EDenied:
       
   443 			{
       
   444 			//load resource
       
   445 			TBuf<100> array(*iCorporate);
       
   446 		  HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_DENIED_NOTE, array);
       
   447 			
       
   448 			//show dialog and get response
       
   449 			response = ShowConfirmationQueryL( *displayString, EFalse);
       
   450 			//delete resource
       
   451 			CleanupStack::PopAndDestroy();
       
   452 			
       
   453 			break;
       
   454 			}		
       
   455 		case EUnMatch:
       
   456 			{
       
   457 			//load resource
       
   458 		    HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_UNMATCH_NOTE);
       
   459 			
       
   460 			//show dialog and get response
       
   461 			response = ShowConfirmationQueryL( *displayString, ETrue);
       
   462 			//delete resource
       
   463 			CleanupStack::PopAndDestroy();
       
   464 			
       
   465 			break;
       
   466 			}
       
   467 		case EQuestion:
       
   468 			{
       
   469 			//question note prompt
       
   470 			TBuf<100> array(*iCorporate);
       
   471     		HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_QUESTION_NOTE,array);
       
   472 			TBuf<RANDOM_PART_MAX_SIZE> input;
       
   473 			TBool ready = EFalse;
       
   474 
       
   475 			//until cancel pressed or valid user gives valid certificate part
       
   476 			while ( !ready)
       
   477 				{
       
   478 				//data query
       
   479 				CPolicyEngineUi::TDlgResp resp = DataQueryL( *displayString, input);
       
   480 				if ( resp == EUserAccept )
       
   481 					{
       
   482 					if ( input.CompareF( *iRandomPart) != 0)
       
   483 						{
       
   484 						//if user input doesn't match
       
   485 						if ( EUserDeny == ShowDialogL( EUnMatch))
       
   486 							{
       
   487 							//if user cancel dialog, show deny-dialog and return
       
   488 							response = EUserDeny;
       
   489 							break;
       
   490 							}			
       
   491 						}
       
   492 					else
       
   493 						{
       
   494 						response = EUserAccept;
       
   495 						ready = ETrue;				
       
   496 						}
       
   497 					}
       
   498 				else
       
   499 					{
       
   500 					//if user cancel dialog, show deny-dialog and return
       
   501 					response = EUserDeny;
       
   502 					break;
       
   503 					}
       
   504 				}	
       
   505 	
       
   506 			//delete resource
       
   507 			CleanupStack::PopAndDestroy();
       
   508 			break;
       
   509 			}
       
   510 		default:
       
   511 		break;
       
   512 		}
       
   513 	
       
   514 	return response;
       
   515 	}
       
   516 
       
   517 
       
   518 CPolicyEngineUi::TDlgResp CPolicyEngineUi::ShowPossessionMessageQueryL()
       
   519 	{
       
   520 	HBufC* securityInfoString = StringLoader::LoadLC( R_POLICYENGINEUI_SECURITY_INFO_NOTE );
       
   521 	TBuf<60> buffer;
       
   522 	buffer.Copy( *securityInfoString );
       
   523 	CleanupStack::PopAndDestroy( securityInfoString );
       
   524 		
       
   525 	//load resource
       
   526 	TBuf<100> array(*iCorporate);
       
   527   HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_CONTROL_NOTE, array);
       
   528 			
       
   529 			
       
   530 	//show dialog and get response
       
   531 	CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *displayString );
       
   532     dlg->PrepareLC( R_POLICY_ENGINE_POSSESSION_INFO );
       
   533     dlg->QueryHeading()->SetTextL( buffer );
       
   534     TInt response = dlg->RunLD();
       
   535     
       
   536     CleanupStack::PopAndDestroy();
       
   537     
       
   538 	if ( response )
       
   539 		{
       
   540 		return EOkResp;
       
   541 		}
       
   542 	
       
   543 	return ECancelResp; 
       
   544 	}
       
   545 
       
   546 
       
   547 
       
   548 
       
   549