os/graphics/windowing/windowserver/nonnga/SERVER/PASSWORD.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Password handling
    15 // 
    16 //
    17 
    18 #include <e32std.h>
    19 #include <w32std.h>
    20 #include "server.h"
    21 #include "rootwin.h"
    22 #include "windowgroup.h"
    23 #include "password.h"
    24 
    25 TBool CWsPassword::iPasswordModeActive=EFalse;
    26 TPasswordMode CWsPassword::iPasswordMode=EPasswordCancel;
    27 CWsClientWindow *CWsPassword::iPasswordWindow=NULL;
    28 TInt CWsPassword::iPrevPasswordDay=-1;
    29 
    30 void CWsPassword::WindowDestroyed(CWsClientWindow *aWindow)
    31 	{
    32 	if (aWindow==iPasswordWindow)
    33 		CancelPasswordWindow();
    34 	}
    35 
    36 void CWsPassword::CancelPasswordWindow()
    37 	{
    38 	iPasswordWindow=NULL;
    39 	iPasswordModeActive=EFalse;
    40 	}
    41 
    42 void CWsPassword::SetPasswordWindowL(CWsClientWindow *aWindow, TPasswordMode aPasswordMode)
    43 	{
    44 	TBool triggerNow=EFalse;
    45 	if (aPasswordMode==EPasswordAlwaysTriggerNow || aPasswordMode==EPasswordOnceADayTriggerNow)
    46 		{
    47 		triggerNow=ETrue;
    48 		if (aPasswordMode==EPasswordOnceADayTriggerNow)
    49 			aPasswordMode=EPasswordOnceADay;
    50 		else
    51 			aPasswordMode=EPasswordAlways;
    52 		}
    53 	if (aPasswordMode==EPasswordCancel)
    54 		{
    55 		if (aWindow!=iPasswordWindow)
    56 			aWindow->OwnerPanic(EWservPanicPassword);
    57 		CancelPasswordWindow();
    58 		}
    59 	else
    60 		{
    61 		if (iPasswordWindow && iPasswordWindow!=aWindow)
    62 			User::Leave(KErrInUse);
    63 		if (aPasswordMode!=EPasswordAlways && aPasswordMode!=EPasswordOnceADay && aPasswordMode!=EPasswordNone)
    64 			aWindow->OwnerPanic(EWservPanicPassword);
    65 		iPasswordWindow=aWindow;
    66 		}
    67 	iPasswordMode=aPasswordMode;
    68 	if (iPasswordMode==EPasswordOnceADay)
    69 		iPrevPasswordDay=-1;	// Force a password to be displayed on the this switch on
    70 	if (triggerNow)
    71 		SwitchOn();
    72 	}
    73 
    74 TInt CWsPassword::Day()
    75 //
    76 // Return the current day taking into account the password midnight offset
    77 //
    78 	{
    79 	TTime now;
    80 	now.HomeTime();
    81 	now-=TTimeIntervalHours(EPasswordMidnightOffset);
    82 	return(now.DateTime().Day());
    83 	}
    84 
    85 void CWsPassword::SwitchOn()
    86 	{
    87 	if (!iPasswordModeActive && iPasswordWindow && iPasswordMode!=EPasswordNone)
    88 		{
    89 		if (iPasswordMode==EPasswordOnceADay)
    90 			{
    91 			TInt oldDay=iPrevPasswordDay;
    92 			iPrevPasswordDay=Day();
    93 			if (iPrevPasswordDay==oldDay)
    94 				return;		// No password display needed
    95 			}
    96 		iPasswordModeActive=ETrue;
    97 		iPasswordWindow->WinGroup()->QueueEvent(EEventPassword);
    98 		iPasswordWindow->WinGroup()->SetOrdinalPriority(0,KPasswordWindowGroupPriority);
    99 		iPasswordWindow->SetOrdinalPosition(0);
   100 		iPasswordWindow->SetVisible(ETrue);
   101 //
   102 		iPasswordWindow->RootWindow()->InvalidateWholeScreen();
   103 		iPasswordWindow->RootWindow()->ClearDisplay();
   104 		}
   105 	}
   106 
   107 void CWsPassword::PasswordEntered(CWsClient *aClient)
   108 	{
   109 	if (!iPasswordWindow || aClient!=iPasswordWindow->WsOwner())
   110 		aClient->PPanic(EWservPanicPassword);
   111 	iPasswordModeActive=EFalse;
   112 	}