sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Password handling sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "W32STD.H" sl@0: #include "server.h" sl@0: #include "rootwin.h" sl@0: #include "windowgroup.h" sl@0: #include "password.h" sl@0: sl@0: TBool CWsPassword::iPasswordModeActive=EFalse; sl@0: TPasswordMode CWsPassword::iPasswordMode=EPasswordCancel; sl@0: CWsClientWindow *CWsPassword::iPasswordWindow=NULL; sl@0: TInt CWsPassword::iPrevPasswordDay=-1; sl@0: sl@0: void CWsPassword::WindowDestroyed(CWsClientWindow *aWindow) sl@0: { sl@0: if (aWindow==iPasswordWindow) sl@0: CancelPasswordWindow(); sl@0: } sl@0: sl@0: void CWsPassword::CancelPasswordWindow() sl@0: { sl@0: iPasswordWindow=NULL; sl@0: iPasswordModeActive=EFalse; sl@0: } sl@0: sl@0: void CWsPassword::SetPasswordWindowL(CWsClientWindow *aWindow, TPasswordMode aPasswordMode) sl@0: { sl@0: TBool triggerNow=EFalse; sl@0: if (aPasswordMode==EPasswordAlwaysTriggerNow || aPasswordMode==EPasswordOnceADayTriggerNow) sl@0: { sl@0: triggerNow=ETrue; sl@0: if (aPasswordMode==EPasswordOnceADayTriggerNow) sl@0: aPasswordMode=EPasswordOnceADay; sl@0: else sl@0: aPasswordMode=EPasswordAlways; sl@0: } sl@0: if (aPasswordMode==EPasswordCancel) sl@0: { sl@0: if (aWindow!=iPasswordWindow) sl@0: aWindow->OwnerPanic(EWservPanicPassword); sl@0: CancelPasswordWindow(); sl@0: } sl@0: else sl@0: { sl@0: if (iPasswordWindow && iPasswordWindow!=aWindow) sl@0: User::Leave(KErrInUse); sl@0: if (aPasswordMode!=EPasswordAlways && aPasswordMode!=EPasswordOnceADay && aPasswordMode!=EPasswordNone) sl@0: aWindow->OwnerPanic(EWservPanicPassword); sl@0: iPasswordWindow=aWindow; sl@0: } sl@0: iPasswordMode=aPasswordMode; sl@0: if (iPasswordMode==EPasswordOnceADay) sl@0: iPrevPasswordDay=-1; // Force a password to be displayed on the this switch on sl@0: if (triggerNow) sl@0: SwitchOn(); sl@0: } sl@0: sl@0: TInt CWsPassword::Day() sl@0: // sl@0: // Return the current day taking into account the password midnight offset sl@0: // sl@0: { sl@0: TTime now; sl@0: now.HomeTime(); sl@0: now-=TTimeIntervalHours(EPasswordMidnightOffset); sl@0: return(now.DateTime().Day()); sl@0: } sl@0: sl@0: void CWsPassword::SwitchOn() sl@0: { sl@0: if (!iPasswordModeActive && iPasswordWindow && iPasswordMode!=EPasswordNone) sl@0: { sl@0: if (iPasswordMode==EPasswordOnceADay) sl@0: { sl@0: TInt oldDay=iPrevPasswordDay; sl@0: iPrevPasswordDay=Day(); sl@0: if (iPrevPasswordDay==oldDay) sl@0: return; // No password display needed sl@0: } sl@0: iPasswordModeActive=ETrue; sl@0: iPasswordWindow->WinGroup()->QueueEvent(EEventPassword); sl@0: iPasswordWindow->WinGroup()->SetOrdinalPriority(0,KPasswordWindowGroupPriority); sl@0: iPasswordWindow->SetOrdinalPosition(0); sl@0: iPasswordWindow->SetVisible(ETrue); sl@0: // sl@0: iPasswordWindow->RootWindow()->InvalidateWholeScreen(); sl@0: iPasswordWindow->RootWindow()->ClearDisplay(); sl@0: } sl@0: } sl@0: sl@0: void CWsPassword::PasswordEntered(CWsClient *aClient) sl@0: { sl@0: if (!iPasswordWindow || aClient!=iPasswordWindow->WsOwner()) sl@0: aClient->PPanic(EWservPanicPassword); sl@0: iPasswordModeActive=EFalse; sl@0: }