sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Password handling
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <w32std.h>
|
sl@0
|
20 |
#include "server.h"
|
sl@0
|
21 |
#include "rootwin.h"
|
sl@0
|
22 |
#include "windowgroup.h"
|
sl@0
|
23 |
#include "password.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
TBool CWsPassword::iPasswordModeActive=EFalse;
|
sl@0
|
26 |
TPasswordMode CWsPassword::iPasswordMode=EPasswordCancel;
|
sl@0
|
27 |
CWsClientWindow *CWsPassword::iPasswordWindow=NULL;
|
sl@0
|
28 |
TInt CWsPassword::iPrevPasswordDay=-1;
|
sl@0
|
29 |
|
sl@0
|
30 |
void CWsPassword::WindowDestroyed(CWsClientWindow *aWindow)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
if (aWindow==iPasswordWindow)
|
sl@0
|
33 |
CancelPasswordWindow();
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
void CWsPassword::CancelPasswordWindow()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
iPasswordWindow=NULL;
|
sl@0
|
39 |
iPasswordModeActive=EFalse;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void CWsPassword::SetPasswordWindowL(CWsClientWindow *aWindow, TPasswordMode aPasswordMode)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
TBool triggerNow=EFalse;
|
sl@0
|
45 |
if (aPasswordMode==EPasswordAlwaysTriggerNow || aPasswordMode==EPasswordOnceADayTriggerNow)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
triggerNow=ETrue;
|
sl@0
|
48 |
if (aPasswordMode==EPasswordOnceADayTriggerNow)
|
sl@0
|
49 |
aPasswordMode=EPasswordOnceADay;
|
sl@0
|
50 |
else
|
sl@0
|
51 |
aPasswordMode=EPasswordAlways;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
if (aPasswordMode==EPasswordCancel)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
if (aWindow!=iPasswordWindow)
|
sl@0
|
56 |
aWindow->OwnerPanic(EWservPanicPassword);
|
sl@0
|
57 |
CancelPasswordWindow();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
else
|
sl@0
|
60 |
{
|
sl@0
|
61 |
if (iPasswordWindow && iPasswordWindow!=aWindow)
|
sl@0
|
62 |
User::Leave(KErrInUse);
|
sl@0
|
63 |
if (aPasswordMode!=EPasswordAlways && aPasswordMode!=EPasswordOnceADay && aPasswordMode!=EPasswordNone)
|
sl@0
|
64 |
aWindow->OwnerPanic(EWservPanicPassword);
|
sl@0
|
65 |
iPasswordWindow=aWindow;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
iPasswordMode=aPasswordMode;
|
sl@0
|
68 |
if (iPasswordMode==EPasswordOnceADay)
|
sl@0
|
69 |
iPrevPasswordDay=-1; // Force a password to be displayed on the this switch on
|
sl@0
|
70 |
if (triggerNow)
|
sl@0
|
71 |
SwitchOn();
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
TInt CWsPassword::Day()
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Return the current day taking into account the password midnight offset
|
sl@0
|
77 |
//
|
sl@0
|
78 |
{
|
sl@0
|
79 |
TTime now;
|
sl@0
|
80 |
now.HomeTime();
|
sl@0
|
81 |
now-=TTimeIntervalHours(EPasswordMidnightOffset);
|
sl@0
|
82 |
return(now.DateTime().Day());
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
void CWsPassword::SwitchOn()
|
sl@0
|
86 |
{
|
sl@0
|
87 |
if (!iPasswordModeActive && iPasswordWindow && iPasswordMode!=EPasswordNone)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
if (iPasswordMode==EPasswordOnceADay)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
TInt oldDay=iPrevPasswordDay;
|
sl@0
|
92 |
iPrevPasswordDay=Day();
|
sl@0
|
93 |
if (iPrevPasswordDay==oldDay)
|
sl@0
|
94 |
return; // No password display needed
|
sl@0
|
95 |
}
|
sl@0
|
96 |
iPasswordModeActive=ETrue;
|
sl@0
|
97 |
iPasswordWindow->WinGroup()->QueueEvent(EEventPassword);
|
sl@0
|
98 |
iPasswordWindow->WinGroup()->SetOrdinalPriority(0,KPasswordWindowGroupPriority);
|
sl@0
|
99 |
iPasswordWindow->SetOrdinalPosition(0);
|
sl@0
|
100 |
iPasswordWindow->SetVisible(ETrue);
|
sl@0
|
101 |
//
|
sl@0
|
102 |
iPasswordWindow->RootWindow()->InvalidateWholeScreen();
|
sl@0
|
103 |
iPasswordWindow->RootWindow()->ClearDisplay();
|
sl@0
|
104 |
}
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
void CWsPassword::PasswordEntered(CWsClient *aClient)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
if (!iPasswordWindow || aClient!=iPasswordWindow->WsOwner())
|
sl@0
|
110 |
aClient->PPanic(EWservPanicPassword);
|
sl@0
|
111 |
iPasswordModeActive=EFalse;
|
sl@0
|
112 |
}
|