// EIKSVDLG.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <e32hal.h>

#include <s32file.h>
#include <txtrich.h>

#include <barsread.h>

#include <apgwgnam.h>

#include <eiksrv.h>
#include "eiksvprv.h"
#include <eiksvdef.h>

#include <eikrted.h>
#include <eikdialg.hrh>
#include <eiktxlbx.h>
#include <eiktxlbm.h>
#include <eikfsel.h>
#include <eikcfdlg.hrh>
#include <eikfutil.h>
#include <eikseced.h>
#include <eikclock.h>
#include <eiklabel.h>

#include <eiksrv.rsg>
#include <eikon.rsg>
#include "eiksrv.hrh"

const TUid KOwnerInfoFileUid={268435691};

CEikDateTime::CEikDateTime()
	{
	iBorder=TEikBorder(TEikBorder::ESingleBlack);
	iContext=this;
	iBrushStyle=CGraphicsContext::ESolidBrush;
	iBrushColor=KRgbWhite;
	}


CEikDateTime::~CEikDateTime()
	{
	delete iDigitalClock;
	}

void CEikDateTime::ConstructL()
	{
	// digital clock
	iDigitalClock=new(ELeave) CEikClock;
	iDigitalClock->SetContainerWindowL(*this);
	TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader, R_EIKPASSWORD_DIGITAL_CLOCK);
	iDigitalClock->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader
	}

void CEikDateTime::SizeChangedL()
	{
	iDigitalClock->SetExtentL(TPoint(iPosition.iX+2,iPosition.iY+2), TSize(iDigitalClock->MinimumSize().iWidth,iDigitalClock->MinimumSize().iHeight+4));
	}

TSize CEikDateTime::MinimumSize()
	{
	TSize size(4,4);
	size+=iDigitalClock->MinimumSize();
	return size;	
	}

void CEikDateTime::Draw(const TRect& /*aRect*/) const
	{
	CGraphicsContext& gc=SystemGc();
	ResetGc();
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.DrawRect(Rect());
	}

TInt CEikDateTime::CountComponentControls() const
	{
	return 1;
	}

CCoeControl* CEikDateTime::ComponentControl(TInt /*aIndex*/) const
	{
	return iDigitalClock;
	}


//
// class CEikPasswordControl
//
 
const TInt KColumns=2;

CEikPasswordControl::CEikPasswordControl(CEikServAppUi* aAppUi)
: iAppUi(aAppUi)
	{
	iBorder=TEikBorder(TEikBorder::EDeepRaisedWithOutline);
	}

CEikPasswordControl::~CEikPasswordControl()
	{
	delete iCaption;
	delete iSeced;
	delete iOwnerInfo;
	delete iAnalogClock;
	delete iDateTime;
	delete iText;
	delete iParaFormatLayer;
	delete iCharFormatLayer;
	iLink.Close(); 
	iEikonEnv->RemoveFromStack(this);
	RWindowGroup& groupWin=iAppUi->AlertGroupWin();
	for (TInt i=0; i<3; i++)
		groupWin.CancelCaptureKey(iAppUi->iExternalKeys[i]);
	}

void CEikPasswordControl::ConstructL()
	{
	CreateWindowL(iAppUi->AlertGroupWin());
	// added by SimonC 16/07/97
	RWindowGroup& groupWin=iAppUi->AlertGroupWin();
	iAppUi->iExternalKeys[0]=groupWin.CaptureKey(KExternalKey1, KExternalKeyModifierMask, KExternalKeyModifier);
	iAppUi->iExternalKeys[1]=groupWin.CaptureKey(KExternalKey2, KExternalKeyModifierMask, KExternalKeyModifier);
	iAppUi->iExternalKeys[2]=groupWin.CaptureKey(KExternalKey3, KExternalKeyModifierMask, KExternalKeyModifier);
	//
	SetPasswordMode();
	SetGloballyCapturing(ETrue);
	Window().SetPointerGrab(ETrue);
	EnableDragEvents();
	CEikonEnv::Static()->AddSleepingAlertDialogToStackL(this);
    iContext=this;
	iBrushColor=KRgbWhite;
    iBrushStyle=CGraphicsContext::ESolidBrush;
    Window().SetBackgroundColor(iBrushColor);


	//create ownerinfo
	iOwnerInfo=new(ELeave) CEikRichTextEditor;
	iOwnerInfo->SetContainerWindowL(*this);
	TResourceReader owninfo;
	iCoeEnv->CreateResourceReaderLC(owninfo, R_EIK_PASSWORD_OWNERINFO);
	iOwnerInfo->ConstructFromResourceL(owninfo);
	CleanupStack::PopAndDestroy(); // owninfo
	iOwnerInfo->SetNonFocusing();
	iOwnerInfo->SetComponentsToInheritVisibility(ETrue);
	iOwnerInfo->CreateScrollBarFrameL();
	iOwnerInfo->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto);
	iParaFormatLayer=iEikonEnv->NewDefaultParaFormatLayerL();
	iCharFormatLayer=iEikonEnv->NewDefaultCharFormatLayerL();
	iText=CRichText::NewL(iParaFormatLayer ,iCharFormatLayer);
	iOwnerInfo->SetDocumentContentL(*iText,CEikEdwin::EUseText);
	iOwnerInfo->CreateTextViewL();

	//password
	iSeced=new(ELeave) CEikServSecretEditor(iAppUi->AlertGroupWin());
	iSeced->SetContainerWindowL(*this);
	TResourceReader seced;
	iCoeEnv->CreateResourceReaderLC(seced, R_EIK_PASSWORD_EDITOR);
	iSeced->ConstructFromResourceL(seced);
	CleanupStack::PopAndDestroy(); // seced
	//	iSeced->SetMaxLength(8);
	iSeced->SetFocus(ETrue);	
	//caption
	iCaption=new(ELeave) CEikLabel;
	iCaption->SetContainerWindowL(*this);
	TResourceReader cap;
	iCoeEnv->CreateResourceReaderLC(cap, R_EIK_PASSWORD_CAPTION);
	iCaption->ConstructFromResourceL(cap);
	CleanupStack::PopAndDestroy(); // cap

	// clocks, date etc
	iAnalogClock=new(ELeave) CEikClock;
	iAnalogClock->SetContainerWindowL(*this);
	TResourceReader aclock;
	iCoeEnv->CreateResourceReaderLC(aclock, R_EIKALARM_ANALOG_CLOCK);
	iAnalogClock->ConstructFromResourceL(aclock);
	CleanupStack::PopAndDestroy(); // aclock
	// digital clock and date
	iDateTime=new(ELeave) CEikDateTime;
	iDateTime->SetContainerWindowL(*this);
	iDateTime->ConstructL();

	MakeVisible(EFalse);
    ActivateL();
	SetExtentToWholeScreenL();
	}

void CEikPasswordControl::ShowPasswordScreen()
	{
	if (IsVisible())
		return;
	iAppUi->BringAlertGroupWinForwards(ETrue);
	DrawableWindow()->SetOrdinalPosition(1); // behind alarm
	ClaimPointerGrab();
	MakeVisible(ETrue);
	iEikonEnv->RouseSleepingDialog(this,ETrue);
	iSeced->Reset();
	TPassword pword;
	if (!Password::IsEnabled() || Password::IsValid(pword))
		{
		if (iSeced->IsVisible())
			{
			iSeced->MakeVisible(EFalse);
			iCaption->MakeVisible(EFalse);
			}
		if (iSeced->IsFocused())
			iSeced->SetFocus(EFalse);
		TRAPD(ret,ConstructOwnerInfoL());
		if (ret!=KErrNone)
			iOwnerInfo->MakeVisible(EFalse);
		return;
		}
	RSemaphore sem;
	if(sem.OpenGlobal(REMOTELINK_CONFIG_SEMAPHORE)==KErrNone)
		{
		if(iLink.Open()==KErrNone)
			iLink.Disable();
		sem.Close();
		}
	iSeced->MakeVisible(ETrue);
	iSeced->SetFocus(ETrue);
	iCaption->MakeVisible(ETrue);
	TRAPD(ret,ConstructOwnerInfoL());// !! can't Leave here - must continue and display the dialog !
	if (ret!=KErrNone)
		iOwnerInfo->MakeVisible(EFalse);
	}

void CEikPasswordControl::ConstructOwnerInfoL()
	{
	iText->Reset();
	CDictionaryStore* iniFile=CDictionaryFileStore::SystemLC(iEikonEnv->FsSession());
	if (iniFile->IsPresentL(KOwnerInfoFileUid))
		{
		RDictionaryReadStream stream;
		stream.OpenL(*iniFile,KOwnerInfoFileUid); // no cleanup stack 
		CEmbeddedStore* store=CEmbeddedStore::FromLC(stream); 
		iText->RestoreL(*store,store->Root());  
		iOwnerInfo->SetDocumentContentL(*iText,CEikEdwin::EUseText);
		CleanupStack::PopAndDestroy(); // embedded store 
	 	CleanupStack::PopAndDestroy(); // inifile
		iOwnerInfo->UpdateScrollBarsL();
		iOwnerInfo->MakeVisible(ETrue);
		return;
		}
 	CleanupStack::PopAndDestroy(); // inifile
	TBuf<256> buf;
	iCoeEnv->ReadResource(buf,R_EIKSRV_PWORDMESSAGE);
	iText->InsertL(0,buf);
	iOwnerInfo->SetDocumentContentL(*iText,CEikEdwin::EUseText);
	iOwnerInfo->UpdateScrollBarsL();
	iOwnerInfo->MakeVisible(ETrue);
	}

TKeyResponse CEikPasswordControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if (aType!=EEventKey)
		return EKeyWasConsumed;
	if (iSeced->IsVisible())	
		{
		if (aKeyEvent.iCode==EKeyEscape)
			{
			iSeced->Reset();
			return EKeyWasConsumed;
			}
		if (aKeyEvent.iCode==EKeyEnter)
			{
			TPassword password;
			iSeced->GetText(password);
			if (Password::IsValid(password))
				ExitPasswordScreen();
			else
				{
				password.Fold();
				if (Password::IsValid(password))
					ExitPasswordScreen();
				else
					iSeced->Reset();
				//iEikonEnv->InfoMsg(R_EIK_TBUF_INCORRECT_PASSWORD);
				}
			return EKeyWasConsumed;
			}
		iSeced->OfferKeyEventL(aKeyEvent,aType);
		return EKeyWasConsumed;
		}
	ExitPasswordScreen();
	return(EKeyWasConsumed);
	}

void CEikPasswordControl::ExitPasswordScreen()
	//
	// ReEnable the remote link if necessary
	//
	{	
	iSeced->Reset();
	iCoeEnv->WsSession().PasswordEntered(); 
	MakeVisible(EFalse);
	iAppUi->BringAlertGroupWinForwards(EFalse);
	CEikonEnv::Static()->RouseSleepingDialog(this,EFalse);
	iEikonEnv->Flush();
	if (iLink.Handle())
		{	
		iLink.Enable(EBps115200, TPtrC(0,0), TPtrC(0,0));
		iLink.Close();
		}
	TPtrC nowt;
	iEikonEnv->SendEventToEikonServer(EEventSwitchOn, &nowt, 0);
	}

void CEikPasswordControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{
	if (iSeced->IsVisible())	 
		{
		CEikBorderedControl::HandlePointerEventL(aPointerEvent);
		return;
		}
	if (aPointerEvent.iType==TPointerEvent::EButton1Down)
		ExitPasswordScreen();
	}


void CEikPasswordControl::SetPasswordMode()
	{
	TPasswordMode mode=EPasswordNone;
	if (Password::IsEnabled())
		mode=EPasswordAlways;	  
	TEikPasswordModeCategory pcategory;
	pcategory.PasswordMode(mode);
	Window().PasswordWindow(mode);
	}

void CEikPasswordControl::SizeChangedL()
	//
	// Layout the components
	//
	{
    TRect rect=iBorder.InnerRect(Rect());
	//ownerinfo	
	TPoint infopoint=rect.iTl;
	infopoint.iX+=6;
	infopoint.iY+=6;
	iOwnerInfo->SetExtentL(infopoint,iOwnerInfo->MinimumSize());
	//analogclock
	TPoint alogpt=iOwnerInfo->Position();
	alogpt.iX+=iOwnerInfo->MinimumSize().iWidth+9;//9 pixels gap
	iAnalogClock->SetExtentL(alogpt,iAnalogClock->MinimumSize());
	//dateclock
	TPoint dtimept=iOwnerInfo->Position();     
	dtimept.iX+=iOwnerInfo->MinimumSize().iWidth; //13 pixels gap
	dtimept.iY+=iAnalogClock->MinimumSize().iHeight+10;  //20 pixels gap
	iDateTime->SetExtentL(dtimept,iDateTime->MinimumSize());

	//caption
	TPoint cappoint=iOwnerInfo->Position(); 
	TInt height=rect.iBr.iY-rect.iTl.iY;
	height-=iOwnerInfo->Size().iHeight;
	TInt capheight=height/2;
	capheight-=iCaption->MinimumSize().iHeight/2;
	cappoint.iY+=iOwnerInfo->Size().iHeight+capheight;
	iCaption->SetExtentL(cappoint,iCaption->MinimumSize());
	//seced
	TPoint secpoint=iCaption->Rect().iTl; 
	secpoint.iX+=iCaption->Size().iWidth + 8;  //gap;
	TSize secedSize=iSeced->MinimumSize();
	secedSize.iHeight+=2; // !!! magic number
	iSeced->SetExtentL(secpoint,secedSize);
	}


TInt CEikPasswordControl::CountComponentControls() const
	{
	return 5;
	}

CCoeControl* CEikPasswordControl::ComponentControl(TInt aIndex) const
	{
	switch (aIndex)
		{
	case 0:
		return iOwnerInfo;
	case 1:
		return iSeced;
	case 2:
		return iCaption;
	case 3:
		return iAnalogClock;
	case 4:
		return iDateTime;
	default:
		return NULL;	
		}
	}

TSize CEikPasswordControl::MinimumSize()
	//
	// MinimumSize is whole screen!
	//
	{
	return iEikonEnv->ScreenDevice()->SizeInPixels();
	}
  
void CEikPasswordControl::Draw(const TRect& /*aRect*/) const

	//
	// Draw border and background
	//
	{
	TRect rect=Rect();
	CGraphicsContext& gc=SystemGc();
	iBorder.Draw(gc,rect);
	TRect innerRect=iBorder.InnerRect(rect);
	gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.DrawRect(innerRect);
	}


//
// CEikServPanicScreen
//

CEikServPanicScreen::CEikServPanicScreen(RThread& aThread)
	: iThread(aThread)
	{
	SetGloballyCapturing(ETrue);
	}
	
void CEikServPanicScreen::PreLayoutDynInitL()
	{
	SetLabelL(EESrvDlgPanicCategory,iThread.ExitCategory());
	SetLabelL(EESrvDlgPanicName,iThread.Name());
	TBuf<8> tmp;
	tmp.Num(iThread.ExitReason());
	SetLabelL(EESrvDlgPanicCode,tmp);
	}

//
// class CEikTaskListDialog
//

CEikTaskListDialog::~CEikTaskListDialog()
	//
	// d'tor
	//
	{
	delete iTasks;
	delete iWgIds;
	delete iWgName;
	}

void CEikTaskListDialog::ConstructL(CEikServAppUi* aEikServAppUi)
	{
	iEikServAppUi=aEikServAppUi;
	iWgName=CApaWindowGroupName::NewL(iEikonEnv->WsSession());
	SetGloballyCapturing(ETrue);
	ConstructSleepingDialogL(R_EIKSRV_TASKLIST_DIALOG);
	ListBox()->SetListBoxObserver(this);
	}

void CEikTaskListDialog::RunTaskListL()
	{
	if (IsVisible())
		return;
	TRAPD(err,PrepareTaskArraysL());
	if (err)
		{
		delete iTasks;
		delete iWgIds;
		iTasks=NULL;
		iWgIds=NULL;
		User::Leave(err);
		}
	RouseSleepingDialog();
	}

TBool CEikTaskListDialog::OkToExitL(TInt aButtonId)
	{
	RWsSession& wsSession=iEikonEnv->WsSession();
	TInt index=ListBoxCurrentItem(EEiksrvTaskListDlgListBox);
	TInt wgId=(*iWgIds)[index];
	TApaTask task(wsSession);
	task.SetWgId(wgId);
	if (aButtonId==EEikBidOk && index) // switch task
		{
		MakeVisible(EFalse);
		task.BringToForeground();
		iEikServAppUi->NotifyAlarmServerOfTaskChange();
		}
	else if (aButtonId==EEikBidDelete) // end task
		{
		EndTaskL(task);
		return EFalse;
		}
	return ETrue;
	}

void CEikTaskListDialog::EndTaskL(TApaTask& aTask)
	//
	// Handle an attempt to kill the selected task
	//
	{
	RWsSession& wsSession=iEikonEnv->WsSession();
	CApaWindowGroupName* wgName=CApaWindowGroupName::NewLC(wsSession, aTask.WgId());
	TPtrC caption=wgName->Caption();
	if (caption.Length())
		{
		if (wgName->IsSystem())
			iEikonEnv->InfoMsg(R_EIKSRV_SYSTEM_TASK_MSG, &caption);
		else 
			{
			if (iLastKeyModifiers&EModifierShift)
				{
				TBuf<128> queryMsg;
				TBuf<32> formatBuf;
				iEikonEnv->ReadResource(formatBuf, R_EIKSRV_KILL_TASK_QUERY);
				queryMsg.Format(formatBuf, &caption);
				TBuf<64> emergMsg;
				iEikonEnv->ReadResource(emergMsg, R_EIKSRV_EMERGENCY_MSG);
				if (iEikonEnv->QueryWinL(queryMsg, emergMsg))
					aTask.KillTask(); // immediate termination
				}
			else
				{
				if (wgName->IsBusy())
					iEikonEnv->InfoMsg(R_EIK_TBUF_APP_BUSY, &caption);
				else
					{
					TBuf<128> queryMsg;
					TBuf<32> formatBuf;
					iEikonEnv->ReadResource(formatBuf, R_EIKSRV_CLOSE_TASK);
					queryMsg.Format(formatBuf, &caption);
					if (iEikonEnv->QueryWinL(queryMsg, _L("")))
						{
						if (!(wgName->RespondsToShutdownEvent()))
							aTask.KillTask(); // immediate termination
						else
							aTask.SendSystemEvent(EApaSystemEventShutdown);
						}
					}
				}
			}
		}
	CleanupStack::PopAndDestroy(); // wgName
	}

void CEikTaskListDialog::PreLayoutDynInitL()
	{
	CEikScrollBarFrame* sbFrame=ListBox()->CreateScrollBarFrameL(ETrue);
	sbFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	SetArrayIntoListBox();
	}

SEikControlInfo CEikTaskListDialog::CreateCustomControlL(TInt aControlType)
	{
	SEikControlInfo ctrlInfo;
	if (aControlType==EEikCtTaskListBox)
		ctrlInfo.iControl=new(ELeave) CEikServTaskListBox;
	else
		ctrlInfo.iControl=NULL;
	ctrlInfo.iTrailerTextId=0;
	ctrlInfo.iFlags=0;
	return ctrlInfo;
	}

void CEikTaskListDialog::PrepareTaskArraysL() 
	{
	delete(iTasks);
	delete(iWgIds);
	iTasks=NULL;
	iWgIds=NULL;
	RWsSession& wsSession=iEikonEnv->WsSession();
	TInt count=wsSession.NumWindowGroups(0);
	if (!count)
		return;
	iTasks=new(ELeave) CDesCArrayFlat(count);
	iWgIds=new(ELeave) CArrayFixFlat<TInt>(count);
	wsSession.WindowGroupList(0,iWgIds);
	TBuf<2*KMaxFileName+1> name;
	count=iWgIds->Count();
	for (TInt ii=0; ii<count; ii++)
		{ 
		TInt wgId=(*iWgIds)[ii];
		iWgName->ConstructFromWgIdL(wgId);
		TPtrC caption=iWgName->Caption();
		if (!(caption.Length())) // not set yet - use thread name instead
			{
			TThreadId threadId;
			TInt err=wsSession.GetWindowGroupClientThreadId(wgId, threadId);
			if (err==KErrNone)
				{
				RThread thread;
				err=thread.Open(threadId);
				if (err==KErrNone)
					{
					name.Copy(thread.Name());
					thread.Close();
					}
				}
			if (err!=KErrNone)
				name.Copy(_L("???")); // !! what to put in here?
			}
		else
			{
			name=caption;
			name.Append(' ');
			TFileName docName=iWgName->DocName();
			if (iEikonEnv->FsSession().IsValidName(docName) && TChar(docName[0]).IsLower())
				{
				TBuf<1> drv=docName.Left(1);
				drv.UpperCase();
				docName.Delete(0,1);
				docName.Insert(0,drv);
				}
			name.Append(docName);
			}
		iTasks->AppendL(name);
		}
	} 

CEikServTaskListBox* CEikTaskListDialog::ListBox() const
	{
	return STATIC_CAST(CEikServTaskListBox*,Control(EEiksrvTaskListDlgListBox));
	}

void CEikTaskListDialog::SetArrayIntoListBox()
	{
	CEikServTaskListBox* listbox=ListBox();
	CTextListBoxModel* model = listbox->Model();
	model->SetItemTextArray(iTasks);
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	listbox->Reset();
	iPrevCurrentItemIndex=0;
	}

TInt CEikTaskListDialog::NumberOfListBoxItems() const
	{
	return ListBox()->Model()->NumberOfItems();
	}

TKeyResponse CEikTaskListDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	iLastKeyModifiers=aKeyEvent.iModifiers;
	TUint code=aKeyEvent.iCode;
	if (aType==EEventKey && code==CTRL('r') && ((iLastKeyModifiers&EAllStdModifiers)==(EModifierCtrl|EModifierFunc)))
		{
		CEikDialog* dialog=new(ELeave) CEikServResetReasonDialog();
		dialog->ExecuteLD(R_EIKSRV_RESET_INFO_DIALOG);
		return EKeyWasConsumed;
		}
	TKeyEvent keyEvent=aKeyEvent;
	keyEvent.iModifiers&=(~EModifierShift);
	return CEikDialog::OfferKeyEventL(keyEvent, aType);
	}

void CEikTaskListDialog::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{
	iLastKeyModifiers=aPointerEvent.iModifiers;
	CEikDialog::HandlePointerEventL(aPointerEvent);
	}

void CEikTaskListDialog::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
	//
	// kludge the double click effect
	//
	{
	if (aEventType==MEikListBoxObserver::EEventItemClicked || aEventType==MEikListBoxObserver::EEventItemDoubleClicked)
		{
		TInt currentItemIndex=aListBox->CurrentItemIndex();
		if (currentItemIndex==iPrevCurrentItemIndex)
			{
			TKeyEvent key;
			key.iCode=EKeyEnter;
			key.iModifiers=0;
			iEikonEnv->SimulateKeyEventL(key,EEventKey);
			}
		iPrevCurrentItemIndex=currentItemIndex;
		}
	}

void CEikTaskListDialog::SetCurrentItemIndex(TInt aCurrentItemIndex)
	//
	// update iPrevCurrentItemIndex	and propogate to listbox
	//
	{
	iPrevCurrentItemIndex=aCurrentItemIndex;
	ListBox()->SetCurrentItemIndex(aCurrentItemIndex);
	}

//
// CEikServTaskListBox
//

void CEikServTaskListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{
	TPointerEvent event=aPointerEvent;
	event.iModifiers&=(~EModifierDoubleClick);
	CEikListBox::HandlePointerEventL(event);
	}

//
// CEikServResetReasonDialog
//

void CEikServResetReasonDialog::PreLayoutDynInitL()
	//
	// Populate the dialog with reset info
	// Debug & tech support use only - hence hard coded text
	// 
	{
	TMachineStartupType reason;
	UserHal::StartupReason(reason);
	TBuf<80> reasonBuf;
	TExcInfo exceptInfo;
	UserHal::ExceptionInfo(exceptInfo);
	switch (reason)
		{
		case EStartupCold:			reasonBuf=(_L("Cold Start")); break;
		case EStartupColdReset: 	reasonBuf=(_L("Cold Reset")); break;
		case EStartupNewOs: 		reasonBuf=(_L("New OS")); break;
		case EStartupPowerFail:		reasonBuf=(_L("Power failed")); break;
		case EStartupWarmReset:		reasonBuf=(_L("Warm Reset")); break;
		case EStartupKernelFault:	
			{
			TUint32 decode[3];
			decode[0]=TUint32(exceptInfo.iCodeAddress);
			decode[1]=TUint32(exceptInfo.iDataAddress);
			decode[2]=0;
			// interpret decode as a null-terminated string
			TPtrC category((TText*)&decode[0]);
			TInt faultno;
			UserHal::FaultReason(faultno);
			if (faultno == 0x10000000)
				reasonBuf=(_L("Kernel Exception"));
			else if (faultno >= 0x10000)
				reasonBuf.Format(_L("Kernel PANIC: %d %S "), faultno-0x10000,&category);
			else
				reasonBuf.Format(_L("Kernel FAULT: %d %S "), faultno,&category);
			}
			break;
		default:
			reasonBuf.Num((TInt)reason);
			break;
		}
	SetLabelL(EESrvResetInfoReason, reasonBuf);
	// last exception
	if (reason >= EStartupPowerFail)
		{
		TBuf<80> lastExceptBuf;
		TInt exceptno;
		UserHal::ExceptionId(exceptno);
		lastExceptBuf.Format(_L("(No. %d: Code 0x%08x Data 0x%08x) "), exceptno, exceptInfo.iCodeAddress,exceptInfo.iDataAddress);
		SetLabelL(EESrvResetInfoLastException, lastExceptBuf);
		}
	else
		SetLineDimmedNow(EESrvResetInfoLastException, ETrue);
	}

//
// CEikScreenCaptureDialog
//

CEikScreenCaptureDialog::CEikScreenCaptureDialog(TDes* aFileName, TBool& aSaveAsMonochromeImage, TInt aTitleId)
	: CEikFileSaveAsDialog(aFileName, NULL, aTitleId, EFalse), iSaveAsMonochrome(aSaveAsMonochromeImage)
	{
	__DECLARE_NAME(_S("CEikScreenCaptureDialog"));
	}
	
TBool CEikScreenCaptureDialog::OkToExitL(TInt aButtonId)
	{
	iSaveAsMonochrome = (ChoiceListCurrentItem(EEikCidImageType) != 0);
	return CEikFileSaveAsDialog::OkToExitL(aButtonId);
	}

