securitydialogs/SecUi/Src/SecUiLockObserver.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Obsererver for Set System Locked event  
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    <e32property.h>
       
    21 #include	<PSVariables.h>
       
    22 #include	<coreapplicationuisdomainpskeys.h>
       
    23 #include <ctsydomainpskeys.h>
       
    24 #include    <securityuisprivatepskeys.h>
       
    25 #include "secuicodequerydialog.h"
       
    26 #include "secui.hrh"
       
    27 #include "SecUiLockObserver.h"
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 //
       
    31 // ----------------------------------------------------------
       
    32 // CSecUiLockObserver::NewL()
       
    33 // Constructs a new entry with given values.
       
    34 // ----------------------------------------------------------
       
    35 //
       
    36 CSecUiLockObserver* CSecUiLockObserver::NewL(CCodeQueryDialog* aDialog, TInt aType)
       
    37     {
       
    38     #if defined(_DEBUG)
       
    39     RDebug::Print(_L("(SECUI)CSecUiLockObserver::NewL() BEGIN"));
       
    40     #endif
       
    41     CSecUiLockObserver* self = new (ELeave) CSecUiLockObserver(aDialog, aType);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop();
       
    45     #if defined(_DEBUG)
       
    46     RDebug::Print(_L("(SECUI)CSecUiLockObserver::NewL() END"));
       
    47     #endif
       
    48     return self;
       
    49     }
       
    50 //
       
    51 // ----------------------------------------------------------
       
    52 // CSecUiLockObserver::CSecUiLockObserver()
       
    53 // Destructor
       
    54 // ----------------------------------------------------------
       
    55 //
       
    56 CSecUiLockObserver::~CSecUiLockObserver()
       
    57     {
       
    58     #if defined(_DEBUG)
       
    59     RDebug::Print(_L("(SECUI)CSecUiLockObserver::~CSecUiLockObserver"));
       
    60     #endif
       
    61     Cancel();
       
    62     }
       
    63 //
       
    64 // ----------------------------------------------------------
       
    65 // CSecUiLockObserver::Start()
       
    66 // Starts listening an event 
       
    67 // ----------------------------------------------------------
       
    68 //
       
    69 TInt CSecUiLockObserver::Start()
       
    70     {
       
    71     #if defined(_DEBUG)
       
    72     RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() BEGIN"));
       
    73     #endif
       
    74     if (IsActive())
       
    75     {
       
    76     #if defined(_DEBUG)
       
    77     RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() In use!!!"));
       
    78     #endif
       
    79     return KErrInUse;
       
    80     }
       
    81         
       
    82     iStatus = KRequestPending;
       
    83     
       
    84     switch(iType)
       
    85         {
       
    86             case ESecUiDeviceLockObserver:
       
    87                 #if defined(_DEBUG)
       
    88                 RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() Device Lock Observer"));
       
    89                 #endif
       
    90                 iProperty.Attach(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus); 
       
    91                 break;
       
    92             
       
    93             case ESecUiRequestStateObserver:
       
    94                     #if defined(_DEBUG)
       
    95                     RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() Request State Observer"));
       
    96                     #endif
       
    97                     iProperty.Attach(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel); 
       
    98                 break;
       
    99             case ESecUiCallStateObserver:
       
   100                 #if defined(_DEBUG)
       
   101                 RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() Call State Observer"));
       
   102                 #endif
       
   103                 iProperty.Attach(KPSUidCtsyCallInformation, KCTsyCallState); 
       
   104                 break;
       
   105             default:
       
   106                 break;
       
   107         }
       
   108     
       
   109     iProperty.Subscribe(iStatus);
       
   110     SetActive();
       
   111     iSubscribedToEvent = ETrue;
       
   112     #if defined(_DEBUG)
       
   113     RDebug::Print(_L("(SECUI)CSecUiLockObserver::Start() END"));
       
   114     #endif
       
   115     return KErrNone;
       
   116     }
       
   117 //
       
   118 // ----------------------------------------------------------
       
   119 // CLockObserver::CLockObserver()
       
   120 // C++ constructor
       
   121 // ----------------------------------------------------------
       
   122 // 
       
   123 CSecUiLockObserver::CSecUiLockObserver(CCodeQueryDialog* aDialog, TInt aType) : CActive(0), iDialog(aDialog), iSubscribedToEvent(EFalse), iType(aType)
       
   124 	{                            
       
   125     }
       
   126 //
       
   127 // ----------------------------------------------------------
       
   128 // CSecUiLockObserver::ConstructL()
       
   129 // Symbian OS default constructor
       
   130 // ----------------------------------------------------------
       
   131 // 
       
   132 void CSecUiLockObserver::ConstructL()
       
   133     {
       
   134     #if defined(_DEBUG)
       
   135     RDebug::Print(_L("(SECUI)CSecUiLockObserver::ConstructL() BEGIN"));
       
   136     #endif
       
   137     // Add this active object to the scheduler.
       
   138 	CActiveScheduler::Add(this);
       
   139 	// Begin obsering PubSub event  
       
   140 	Start();
       
   141 	#if defined(_DEBUG)
       
   142     RDebug::Print(_L("(SECUI)CSecUiLockObserver::ConstructL() END"));
       
   143     #endif	
       
   144     }
       
   145 //
       
   146 // ----------------------------------------------------------
       
   147 // CSecUiLockObserver::RunL()
       
   148 // Called by Active Scheduler
       
   149 // ----------------------------------------------------------
       
   150 // 
       
   151 void CSecUiLockObserver::RunL()
       
   152 	{
       
   153 	#if defined(_DEBUG)
       
   154     RDebug::Print(_L("(SECUI)CSecUiLockObserver::RunL() BEGIN"));
       
   155     #endif
       
   156     
       
   157     switch(iType)
       
   158         {
       
   159             case ESecUiDeviceLockObserver:
       
   160                  TInt autolockState;
       
   161                  iProperty.Get( autolockState );
       
   162                  if (autolockState > EAutolockOff)
       
   163                     {
       
   164                     #if defined(_DEBUG)
       
   165                     RDebug::Print(_L("(SECUI)CSecUiLockObserver::RunL() TryCancelQueryL Device Lock"));
       
   166                     #endif
       
   167                 	iDialog->TryCancelQueryL(ESecUiDeviceLocked);
       
   168                 	iSubscribedToEvent = EFalse;
       
   169                     }
       
   170                 break;
       
   171             
       
   172             case ESecUiRequestStateObserver:
       
   173                  TInt requestState;
       
   174                  iProperty.Get( requestState );
       
   175                  if(requestState == ESecurityUIsQueryRequestCanceled)
       
   176                     {
       
   177                      #if defined(_DEBUG)
       
   178                     RDebug::Print(_L("(SECUI)CSecUiLockObserver::RunL() TryCancelQueryL Req Canceled"));
       
   179                     #endif
       
   180                 	iDialog->TryCancelQueryL(EEikBidCancel);
       
   181                 	iSubscribedToEvent = EFalse;   
       
   182                     }
       
   183                 break;
       
   184             case ESecUiCallStateObserver:
       
   185                 TInt callState;
       
   186                 iProperty.Get( callState );
       
   187                 if(callState > EPSCTsyCallStateNone)
       
   188                     {
       
   189                      #if defined(_DEBUG)
       
   190                     RDebug::Print(_L("(SECUI)CSecUiLockObserver::RunL() TryCancelQueryL Active Call"));
       
   191                     #endif
       
   192                 	iDialog->TryCancelQueryL(EEikBidCancel);
       
   193                 	iSubscribedToEvent = EFalse;   
       
   194                     }
       
   195                 break;
       
   196             default:
       
   197                 break;
       
   198         }
       
   199 
       
   200    
       
   201 	#if defined(_DEBUG)
       
   202     RDebug::Print(_L("(SECUI)CSecUiLockObserver::RunL() END"));
       
   203     #endif
       
   204 	}
       
   205 //
       
   206 // ----------------------------------------------------------
       
   207 // CSecUiLockObserver::DoCancel()
       
   208 // Cancels event listening
       
   209 // ----------------------------------------------------------
       
   210 // 
       
   211 void CSecUiLockObserver::DoCancel()
       
   212     {
       
   213     #if defined(_DEBUG)
       
   214     RDebug::Print(_L("(SECUI)CSecUiLockObserver::DoCancel() BEGIN"));
       
   215     #endif
       
   216     if(iSubscribedToEvent)
       
   217     	iProperty.Cancel();
       
   218     iStatus = KErrNone;
       
   219     #if defined(_DEBUG)
       
   220     RDebug::Print(_L("(SECUI)CSecUiLockObserver::DoCancel() END"));
       
   221     #endif
       
   222     }
       
   223 //
       
   224 // ----------------------------------------------------------
       
   225 // CSecUiLockObserver::StopObserver()
       
   226 // Cancels event listening
       
   227 // ----------------------------------------------------------
       
   228 //     
       
   229 void CSecUiLockObserver::StopObserver()
       
   230 	{
       
   231 	#if defined(_DEBUG)
       
   232     RDebug::Print(_L("(SECUI)CSecUiLockObserver::StopObserver() BEGIN"));
       
   233     #endif
       
   234     Cancel();
       
   235     #if defined(_DEBUG)
       
   236     RDebug::Print(_L("(SECUI)CSecUiLockObserver::StopObserver() END"));
       
   237     #endif
       
   238     }
       
   239 //
       
   240 // ----------------------------------------------------------
       
   241 // CSecUiLockObserver::StartObserver()
       
   242 // Start event listening
       
   243 // ----------------------------------------------------------
       
   244 //     
       
   245 void CSecUiLockObserver::StartObserver()
       
   246 	{
       
   247 	#if defined(_DEBUG)
       
   248     RDebug::Print(_L("(SECUI)CSecUiLockObserver::StartObserver() BEGIN"));
       
   249     #endif
       
   250     Start();
       
   251     #if defined(_DEBUG)
       
   252     RDebug::Print(_L("(SECUI)CSecUiLockObserver::StartObserver() END"));
       
   253     #endif
       
   254     }
       
   255 //
       
   256 // ----------------------------------------------------------
       
   257 // CSecUiLockObserver::SetAddress()
       
   258 // Start event listening
       
   259 // ----------------------------------------------------------
       
   260 //  
       
   261 void CSecUiLockObserver::SetAddress(CCodeQueryDialog* aDialog)
       
   262 {
       
   263 	#if defined(_DEBUG)
       
   264     RDebug::Print(_L("(SECUI)CSecUiLockObserver::SetAddress() BEGIN"));
       
   265     #endif
       
   266 	iDialog = aDialog;
       
   267 	#if defined(_DEBUG)
       
   268     RDebug::Print(_L("(SECUI)CSecUiLockObserver::SetAddress() END"));
       
   269     #endif
       
   270 }
       
   271 // End of file