Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include "windowgroup.h"
25 TBool CWsPassword::iPasswordModeActive=EFalse;
26 TPasswordMode CWsPassword::iPasswordMode=EPasswordCancel;
27 CWsClientWindow *CWsPassword::iPasswordWindow=NULL;
28 TInt CWsPassword::iPrevPasswordDay=-1;
30 void CWsPassword::WindowDestroyed(CWsClientWindow *aWindow)
32 if (aWindow==iPasswordWindow)
33 CancelPasswordWindow();
36 void CWsPassword::CancelPasswordWindow()
39 iPasswordModeActive=EFalse;
42 void CWsPassword::SetPasswordWindowL(CWsClientWindow *aWindow, TPasswordMode aPasswordMode)
44 TBool triggerNow=EFalse;
45 if (aPasswordMode==EPasswordAlwaysTriggerNow || aPasswordMode==EPasswordOnceADayTriggerNow)
48 if (aPasswordMode==EPasswordOnceADayTriggerNow)
49 aPasswordMode=EPasswordOnceADay;
51 aPasswordMode=EPasswordAlways;
53 if (aPasswordMode==EPasswordCancel)
55 if (aWindow!=iPasswordWindow)
56 aWindow->OwnerPanic(EWservPanicPassword);
57 CancelPasswordWindow();
61 if (iPasswordWindow && iPasswordWindow!=aWindow)
62 User::Leave(KErrInUse);
63 if (aPasswordMode!=EPasswordAlways && aPasswordMode!=EPasswordOnceADay && aPasswordMode!=EPasswordNone)
64 aWindow->OwnerPanic(EWservPanicPassword);
65 iPasswordWindow=aWindow;
67 iPasswordMode=aPasswordMode;
68 if (iPasswordMode==EPasswordOnceADay)
69 iPrevPasswordDay=-1; // Force a password to be displayed on the this switch on
74 TInt CWsPassword::Day()
76 // Return the current day taking into account the password midnight offset
81 now-=TTimeIntervalHours(EPasswordMidnightOffset);
82 return(now.DateTime().Day());
85 void CWsPassword::SwitchOn()
87 if (!iPasswordModeActive && iPasswordWindow && iPasswordMode!=EPasswordNone)
89 if (iPasswordMode==EPasswordOnceADay)
91 TInt oldDay=iPrevPasswordDay;
92 iPrevPasswordDay=Day();
93 if (iPrevPasswordDay==oldDay)
94 return; // No password display needed
96 iPasswordModeActive=ETrue;
97 iPasswordWindow->WinGroup()->QueueEvent(EEventPassword);
98 iPasswordWindow->WinGroup()->SetOrdinalPriority(0,KPasswordWindowGroupPriority);
99 iPasswordWindow->SetOrdinalPosition(0);
100 iPasswordWindow->SetVisible(ETrue);
102 iPasswordWindow->RootWindow()->InvalidateWholeScreen();
103 iPasswordWindow->RootWindow()->ClearDisplay();
107 void CWsPassword::PasswordEntered(CWsClient *aClient)
109 if (!iPasswordWindow || aClient!=iPasswordWindow->WsOwner())
110 aClient->PPanic(EWservPanicPassword);
111 iPasswordModeActive=EFalse;