securitydialogs/Autolock/src/AutoLockCenRepI.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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h> 
       
    20 #include <settingsinternalcrkeys.h>
       
    21 #include "AutoLockModelPS.h"
       
    22 #include "AutolockAppUiPS.h"
       
    23 #include "AutoLockCenRepI.h"
       
    24  
       
    25 
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 //
       
    29 // ----------------------------------------------------------
       
    30 // CAutolockCenRepI::NewLC()
       
    31 // Two-phased constructor.
       
    32 // ----------------------------------------------------------
       
    33 //
       
    34 CAutolockCenRepI* CAutolockCenRepI::NewLC(CAutolockAppUi* aAppUi)
       
    35 	{
       
    36 	CAutolockCenRepI* self = new (ELeave) CAutolockCenRepI(aAppUi);
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 //
       
    43 // ----------------------------------------------------------
       
    44 // CAutolockCenRepI::NewL()
       
    45 // Two-phased constructor.
       
    46 // ----------------------------------------------------------
       
    47 //
       
    48 CAutolockCenRepI* CAutolockCenRepI::NewL(CAutolockAppUi* aAppUi)
       
    49 	{
       
    50 	CAutolockCenRepI* self = NewLC(aAppUi);
       
    51 	CleanupStack::Pop(); //self
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 //
       
    56 // ----------------------------------------------------------
       
    57 // CAutolockCenRepI::~CAutolockCenRepI()
       
    58 // Destructor
       
    59 // ----------------------------------------------------------
       
    60 //
       
    61 CAutolockCenRepI::~CAutolockCenRepI()
       
    62 	{
       
    63 	if(iNotifyHandler)
       
    64 	{
       
    65 		iNotifyHandler->StopListening();
       
    66 		delete iNotifyHandler;	
       
    67 	}
       
    68     if(iSession)
       
    69 		delete iSession;
       
    70 	}
       
    71 //
       
    72 // ----------------------------------------------------------
       
    73 // CAutolockCenRepI::CAutolockCenRepI()
       
    74 // C++ default constructor
       
    75 // ----------------------------------------------------------
       
    76 //	
       
    77 CAutolockCenRepI::CAutolockCenRepI(CAutolockAppUi* aAppUi):iAppUi(aAppUi)
       
    78 	{
       
    79 	}
       
    80 
       
    81 //
       
    82 // ----------------------------------------------------------
       
    83 // CAutolockCenRepI::ConstructL()
       
    84 // Symbian OS default constructor
       
    85 // ----------------------------------------------------------
       
    86 //	
       
    87 void CAutolockCenRepI::ConstructL()
       
    88 	{
       
    89 	// init cenrep connection	
       
    90 	iSession = CRepository::NewL(KCRUidSecuritySettings);
       
    91 
       
    92     iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iSession, CCenRepNotifyHandler::EIntKey, KSettingsAutoLockTime);
       
    93     iNotifyHandler->StartListeningL();
       
    94 	}
       
    95 
       
    96 //
       
    97 // ----------------------------------------------------------
       
    98 // CAutolockCenRepI::HandleNotifyInt()
       
    99 // Handles autolock period changes. Called by CenRep.
       
   100 // ----------------------------------------------------------
       
   101 //	
       
   102 void CAutolockCenRepI::HandleNotifyInt(TUint32 aId, TInt /*aNewValue*/)
       
   103 	{
       
   104     if(aId == KSettingsAutoLockTime)
       
   105     {
       
   106 	    ResetInactivityTimeout();
       
   107     }
       
   108 	return;
       
   109 	}
       
   110 
       
   111 void CAutolockCenRepI::HandleNotifyError(TUint32 /*aId*/, TInt /*error*/, CCenRepNotifyHandler* /*aHandler*/)
       
   112     {
       
   113     return;
       
   114     }
       
   115 
       
   116 void CAutolockCenRepI::HandleNotifyGeneric(TUint32 aId)
       
   117     {
       
   118         if ( aId == NCentralRepositoryConstants::KInvalidNotificationId )
       
   119         {//Repository wide reset caused generic notification
       
   120             ResetInactivityTimeout();
       
   121         }
       
   122     return;
       
   123     }
       
   124 
       
   125 //
       
   126 // ----------------------------------------------------------
       
   127 // CAutolockCenRepI::ResetInactivityTimeoutL()
       
   128 // Resets autolock timer
       
   129 // ----------------------------------------------------------
       
   130 //	
       
   131 void CAutolockCenRepI::ResetInactivityTimeout()
       
   132 	{
       
   133 	iAppUi->Model()->ResetInactivityTimeout();
       
   134 	}
       
   135 
       
   136 //
       
   137 // ----------------------------------------------------------
       
   138 // CAutolockCenRepI::Timeout()
       
   139 // Returns currents autolock period (in seconds)
       
   140 // ----------------------------------------------------------
       
   141 //	
       
   142 TInt CAutolockCenRepI::Timeout()
       
   143 	{
       
   144     TInt period = 0;
       
   145     iSession->Get(KSettingsAutoLockTime, period);
       
   146 	return period * 60;
       
   147 	}
       
   148 //
       
   149 // ----------------------------------------------------------
       
   150 // CAutolockCenRepI::SetLocked ()
       
   151 // Sets lock on/off in CenRep
       
   152 // ----------------------------------------------------------
       
   153 //	
       
   154 void CAutolockCenRepI::SetLockedL(TBool aLockValue)
       
   155 	{
       
   156 	TInt lockValue = 0;
       
   157 	if (aLockValue)
       
   158 		{
       
   159 		lockValue = 1;
       
   160 		}
       
   161     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
       
   162     repository->Set(KSettingsAutolockStatus, lockValue);
       
   163     delete repository;
       
   164 	}
       
   165 // END OF FILE