policymanagement/policyengine/policyengineui/src/PolicyEngineUi.cpp
branchRCL_3
changeset 61 b183ec05bd8c
parent 58 4af31167ea77
child 62 19bba8228ff0
equal deleted inserted replaced
59:13d7c31c74e0 61:b183ec05bd8c
     1 /*
     1 /*
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2000 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:  This file contains the implementation of PolicyEngineUI
    14 * Description: Implementation of policymanagement components
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 #include "PolicyEngineUI.h"
    19 // INCLUDE FILES
    19 #include <hbpopup.h>
    20 #include "PolicyEngineUi.h"
    20 #include <hbinputdialog.h>
    21 #include "debug.h"
    21 #include <hbdocumentloader.h>
    22 #include "policyengineui.hrh"
    22 #include <hbdialog.h>
    23 #include <policyengineuidlgs.rsg>
    23 #include <hblabel.h>
    24 
    24 #include <hbaction.h>
    25 #include <bautils.h>
    25 #include <hbnotificationdialog.h>
    26 #include <eikenv.h>
    26 #include <hbmessagebox.h>
    27 #include <StringLoader.h>
    27 #include <hbdevicenotificationdialog.h>
    28 #include <AknQueryDialog.h>
    28 #include "Logger.h"
    29 #include <eikprogi.h>
    29 
    30 #include <aknnotewrappers.h>
    30 const int KMaxTries = 4;
    31 #include <aknmessagequerydialog.h>
    31 const int KMaxCodeLength = 4;
    32 #include <data_caging_path_literals.hrh>
    32 
    33 #include "SyncService.h"
    33 
    34 
    34 // -----------------------------------------------------------------------------
    35 #include <implementationproxy.h>
    35 // PolicyEngineUI::PolicyEngineUI()
    36 
    36 // -----------------------------------------------------------------------------
    37 
    37 PolicyEngineUI::PolicyEngineUI(const QVariantMap& parameters)
    38 _LIT( KCUIResourceFileName, "PolicyEngineUIDlgs.rsc" );
    38     {
    39 const TUid KUidPolicyEngineUi = { 0x10207817 };
    39     estbTrustCount = KMaxTries;
    40 const TUid KScreenOutputChannel = { 0x0000781F };
    40     DisplayNotificationDialog(parameters);
    41 
    41     }
    42 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers );
    42 
    43 
    43 
    44 
    44 // -----------------------------------------------------------------------------
    45 // ---------------------------------------------------------
    45 // PolicyEngineUI::~PolicyEngineUI()
    46 // CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
    46 // -----------------------------------------------------------------------------
    47 // ---------------------------------------------------------
    47 PolicyEngineUI::~PolicyEngineUI()
    48 //
    48     {
    49 
    49 
    50 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers )
    50     }
    51 {
    51 
    52     MEikSrvNotifierBase2 *policyEngineNotifier = CPolicyEngineNotifier::NewL();
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // PolicyEngineUI::DisplayNotificationDialog()
       
    55 // Read the parameters sent from client
       
    56 // -----------------------------------------------------------------------------
       
    57 void PolicyEngineUI::DisplayNotificationDialog(const QVariantMap& parameters)
       
    58     {
       
    59     LOGSTRING( "+ DisplayNotificationDialog +" );
       
    60     QVariantMap::const_iterator i = parameters.constBegin();
       
    61 
       
    62     while (i != parameters.constEnd())
       
    63         {
       
    64         if (i.key().toAscii() == "serverdisplayname")
       
    65             {
       
    66             iServerName = i.value().toString();
       
    67             }
       
    68         else if (i.key().toAscii() == "fingerprint")
       
    69             {
       
    70             iFingerprint = i.value().toString();
       
    71             }
       
    72         ++i;
       
    73         }
    53     
    74     
    54     CleanupStack::PushL( policyEngineNotifier );
    75     TBuf<50> server(iServerName.utf16());
    55     aNotifiers->AppendL( policyEngineNotifier );
    76     TBuf<10> buffer(iFingerprint.utf16());
    56     CleanupStack::Pop( policyEngineNotifier ); // serNotify
    77 
    57 	RDEBUG("PolicyEngineUI notifier created!");
    78     LOGSTRING2( "serverdisplayname %S", &server );
    58 }
    79     LOGSTRING2( "fingerprint %S", &buffer );
    59 
    80 
    60 
    81     ShowInputDialog();
    61 
    82     LOGSTRING( "- DisplayNotificationDialog -" );
    62 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
    83     }
    63     { 
    84 
    64     CArrayPtrFlat<MEikSrvNotifierBase2>* array =
    85 
    65     new CArrayPtrFlat<MEikSrvNotifierBase2>( 1 );
    86 // -----------------------------------------------------------------------------
    66 
    87 // PolicyEngineUI::ShowInputDialog()
    67     if (array)
    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)
    68         {
    97         {
    69         TRAPD( err, CreateNotifiersL( array ) );
    98         return;
    70         if (err != KErrNone)
    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)
    71             {
   262             {
    72             delete array;
   263             //Access denied.
    73             array = NULL;
   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();
    74             }
   336             }
    75         }
   337         }
    76     return array;
   338     LOGSTRING( "- establishTrust -" );
    77     }
   339     }
    78 
   340 
    79 const TImplementationProxy ImplementationTable[] = { {{0x10207817},(TProxyNewLPtr)NotifierArray} };
   341 
    80 
   342 // -----------------------------------------------------------------------------
    81 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   343 // PolicyEngineUI::cancelTrust()
    82 	{
   344 // -----------------------------------------------------------------------------
    83 	RDEBUG("PolicyEngineUI notifier detected!");
   345 void PolicyEngineUI::cancelTrust()
    84 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy) ;
   346     {
    85 	return ImplementationTable;
   347     LOGSTRING( "+ cancelTrust +" );
    86 	}
   348     //Reset the counter.
    87 
   349     estbTrustCount = 0;
    88 
   350 
    89 
   351     QVariantMap result;
    90 CPolicyEngineNotifier::CPolicyEngineNotifier()
   352     result.insert("keyResponse", -1);
    91 	{
   353     emit
    92 	}
   354     deviceDialogData(result);
    93 
   355 
    94 
   356     emit
    95 CPolicyEngineNotifier::~CPolicyEngineNotifier()
   357     deviceDialogClosed();
    96 	{
   358     LOGSTRING( "- cancelTrust -" );
    97 	//delete and close policy engine ui
   359     }
    98 	delete iPolicyEngineUi;	
   360 
    99 	}
   361 
   100 
   362 // -----------------------------------------------------------------------------
   101 
   363 // PolicyEngineUI::setDeviceDialogParameters()
   102 CPolicyEngineNotifier* CPolicyEngineNotifier::NewL()
   364 // -----------------------------------------------------------------------------
   103 	{
   365 bool PolicyEngineUI::setDeviceDialogParameters(const QVariantMap &parameters)
   104 	CPolicyEngineNotifier* self = new (ELeave) CPolicyEngineNotifier();
   366     {
   105 	
   367 	Q_UNUSED(parameters);
   106 	CleanupStack::PushL( self);
   368     LOGSTRING( "+ setDeviceDialogParameters +" );
   107 	self->ConstructL();	
   369     return true;
   108 	CleanupStack::Pop();
   370     }
   109 	
   371 
   110 	return self;
   372 
   111 	}
   373 // -----------------------------------------------------------------------------
   112 
   374 // PolicyEngineUI::deviceDialogError()
   113 void CPolicyEngineNotifier::ConstructL()
   375 // Get error
   114 	{
   376 // -----------------------------------------------------------------------------
   115 	}
   377 int PolicyEngineUI::deviceDialogError() const
   116 		
   378     {
   117 
   379     LOGSTRING( "+ deviceDialogError +" );
   118 void CPolicyEngineNotifier::Release()
   380     return 0;
   119 	{
   381     }
   120 	delete this;	
   382 
   121 	}
   383 
   122 
   384 // -----------------------------------------------------------------------------
   123 
   385 // PolicyEngineUI::PolicyEngineUI()
   124 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::RegisterL()
   386 // Close device dialog
   125 	{
   387 // -----------------------------------------------------------------------------
   126 	//Registration info
   388 void PolicyEngineUI::closeDeviceDialog(bool byClient)
   127     iInfo.iUid = KUidPolicyEngineUi;
   389     {
   128     iInfo.iPriority = ENotifierPriorityHigh;
   390 	Q_UNUSED(byClient);
   129 	iInfo.iChannel = KScreenOutputChannel;	
   391     LOGSTRING( "+ closeDeviceDialog +" );
   130 	
   392     close();
   131 	return iInfo;
   393     }
   132 	}
   394 
   133 
   395 
   134 
   396 // -----------------------------------------------------------------------------
   135 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::Info() const
   397 // PolicyEngineUI::PolicyEngineUI()
   136 	{
   398 // Return display widget
   137 	//Registration info
   399 // -----------------------------------------------------------------------------
   138 	return iInfo;
   400 HbDialog *PolicyEngineUI::deviceDialogWidget() const
   139 	}
   401     {
   140 
   402     LOGSTRING( "+ deviceDialogWidget +" );
   141 
   403     return const_cast<PolicyEngineUI*> (this);
   142 TPtrC8 CPolicyEngineNotifier::StartL(const TDesC8& /*aBuffer*/)
   404     }
   143 	{
   405 
   144 	return KNullDesC8().Ptr();
   406 
   145 	}
   407 // -----------------------------------------------------------------------------
   146 
   408 // PolicyEngineUI::PolicyEngineUI()
   147 
   409 // Verify the user entered code
   148 void CPolicyEngineNotifier::Complete( TUserResponse aResponse)
   410 // -----------------------------------------------------------------------------
   149 	{
   411 bool PolicyEngineUI::verifyFingerPrint()
   150 	RDEBUG("CPolicyEngineNotifier::Complete");
   412     {
   151 
   413     LOGSTRING( "+ verifyFingerPrint +" );
   152 	//Write return value to message and compeltes it
   414 
   153 	if ( aResponse == EUserAccept )
   415     QString enteredCode = mContentEdit->text();
   154 		{
   416     TBuf<10> buffer(enteredCode.utf16());
   155 		iMessage.Write( iReplySlot, KUserAcceptMark, 0);	
   417 
   156 		}
   418     LOGSTRING2( "User entered code %i", &buffer);
   157 	else
   419     LOGSTRING2( "User entered code %S", &buffer);
   158 		{
   420 
   159 		iMessage.Write( iReplySlot, KUserDenyMark, 0);	
   421     if (enteredCode.compare(iFingerprint, Qt::CaseInsensitive) == 0)
   160 		}
   422     {
   161 	
   423         LOGSTRING( "+ fingerprint MATCH !!!! +" );
   162     iManager->CancelNotifier( iInfo.iUid );   // Notify framework we've done
   424         return true;
   163 	iMessage.Complete( KErrNone);
   425     }
   164 	}
   426     else
   165 
   427     {
   166 
   428         LOGSTRING( "+  fingerprint DOESNOT MATCH  +" );
   167 void CPolicyEngineNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
   429         return false;
   168 	{
   430     }
   169 	RDEBUG("CPolicyEngineNotifier::StartL!");
   431     }
   170 
   432 
   171 	TInt index = aBuffer.Locate( KDelimeterChar);
   433 
   172 	
   434 // -----------------------------------------------------------------------------
   173 	if ( index != KErrNotFound && !iPolicyEngineUi)
   435 // PolicyEngineUI::codeTextChanged()
   174 		{	
   436 // checks the entered text length and enables the OK option accordingly.
   175 		//decode name and fingerprint from message
   437 // -----------------------------------------------------------------------------
   176 		TPtrC8 name = aBuffer.Left( index);
   438 void PolicyEngineUI::codeTextChanged()
   177 		TPtrC8 fingerPrint = aBuffer.Mid( index + 1);
   439     {
   178 
   440     QString str = mContentEdit->text();
   179 		iReplySlot = aReplySlot;
   441 
   180 		iMessage = aMessage;
   442     if (str.length() >= KMaxCodeLength)
   181 
   443         mdialog->actions().at(0)->setEnabled(true);
   182 		//Show policy engine ui dialogs
   444     else
   183 		iPolicyEngineUi = CPolicyEngineUi::NewL();
   445         mdialog->actions().at(0)->setEnabled(false);
   184 		iPolicyEngineUi->ActivateL( name, fingerPrint, this);
   446     }
   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()
       
   214     {
       
   215 	RDEBUG("CPolicyEngineUi::ConstructL!");
       
   216 
       
   217     //get pointer to CEikonEnv
       
   218 	iCoeEnv = CEikonEnv::Static();    
       
   219     
       
   220     if ( !iCoeEnv )
       
   221     	{
       
   222 		RDEBUG("Policy engine ui: CoeEnv not found!");
       
   223         User::Leave( KErrGeneral );        
       
   224     	}
       
   225 
       
   226 	//Open resource file
       
   227     TFileName fileName;
       
   228     fileName.Zero();
       
   229 
       
   230     TFileName drivePath;
       
   231     Dll::FileName( drivePath );
       
   232 
       
   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*/ )
       
   344     {
       
   345        return KErrNone;
       
   346     }	
       
   347 
       
   348 void CPolicyEngineUi::DoCancel()
       
   349 	{
       
   350 	}
       
   351 
       
   352 
       
   353 
       
   354 CPolicyEngineUi::TDlgResp CPolicyEngineUi::ShowConfirmationQueryL( 
       
   355 	const TDesC& aText, const TBool& aWithCancel)
       
   356 	{
       
   357 	//create dialog
       
   358     CAknQueryDialog* note = 
       
   359         CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   360 				
       
   361 	//select correct text resource 					 
       
   362 	TInt resource = R_POLICYENGINEUI_CONFIRMATION_QUERY;
       
   363 	
       
   364 	if ( !aWithCancel )
       
   365 		{
       
   366 		resource = R_POLICYENGINEUI_CONFIRMATION;
       
   367 		}			   
       
   368 						
       
   369 	//execute dialog, dialog contains self destruction			 
       
   370     TInt response = note->ExecuteLD( resource, aText );
       
   371     
       
   372 	if ( response )
       
   373 		{
       
   374 		return EOkResp;
       
   375 		}
       
   376 	
       
   377 	return ECancelResp;
       
   378 	}
       
   379 
       
   380 
       
   381 CPolicyEngineUi::TDlgResp CPolicyEngineUi::DataQueryL( const TDesC& aText, TDes& aInput )
       
   382 	{
       
   383 
       
   384 	//Create dialog with reference to input descriptor
       
   385 	CAknTextQueryDialog* dlg = 
       
   386 		CAknTextQueryDialog::NewL( aInput, CAknQueryDialog::ENoTone);
       
   387 
       
   388 	//set prompt
       
   389 	CleanupStack::PushL( dlg);
       
   390 	dlg->SetPromptL( aText);
       
   391 	CleanupStack::Pop();
       
   392 	
       
   393 	//execute dialog, dialog contains self destruction			 
       
   394 	TInt response = dlg->ExecuteLD( R_POLICYENGINEUI_DATA_QUERY);
       
   395 	
       
   396 	if ( response )
       
   397 		{
       
   398 		return EOkResp;
       
   399 		}
       
   400 	
       
   401 	return ECancelResp;
       
   402 	}
       
   403 
       
   404 
       
   405 TInt CPolicyEngineUi::ShowDialogL( const TDialog& aDialog)
       
   406 	{
       
   407 	TInt response = EUserDeny;
       
   408 
       
   409 	//select correct dialog
       
   410 	switch ( aDialog)
       
   411 		{
       
   412 		case EControl : 
       
   413 			{
       
   414 			response = ShowPossessionMessageQueryL();
       
   415 			break;
       
   416 			}
       
   417 		case ERemove:
       
   418 			{
       
   419 			//load resource
       
   420 		    HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_TRUST_ESTABLISHED );
       
   421 			
       
   422 			TInt length1 = displayString->Length();
       
   423 			HBufC16* trustString = HBufC16::NewLC ( length1  );
       
   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