/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/

// Guide.cpp : implementation file
//

#include "stdafx.h"
#include "scts3devman.h"
#include "Guide.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGuide dialog

static char *guides[][10]=
{
	{
		"Testing a server",
		"Click on the 'Add Test Account' toolbar button or select the '+ Test Account' menu item from the 'Configuration' menu.",
		"In the 'Test Account Information' pane enter the user name and password of the account to be used by SCTS. In the 'Test Object Information' pane select 'Server', after entering the other information click the 'Apply Changes' button.",
		"Configure the test device (Encoding, SyncML protocol...). In the 'Transport Information' pane select the transport protocol and enter the server's address, then click the 'Apply Changes' button.",
		"Click on the 'System Databases' item under the account just created in the 'Accounts' pane, then click the '+ Add Database' toolbar button.",
		"In the 'Database Information' pane enter the same URI used by the server for a particular database and choose the appropriate MIME type, then click the 'Apply Changes' button.",
		"Repeat steps 4 abd 5 for all the databases on the server which are to be tested. Then click on the 'Tests' item under the account just created, double-click a test group and then click on the 'Execute Test' button.",
		0,
	},
	{
		"Testing a Client",
		"Click on '+ Test Account' on the toolbar or select 'Add Test Account' in the 'Configuration menu'.",
		"In the 'Test Account Information' pane, enter the user name and password of the account (Client should use this userid and password to connect to this account). In the 'Test Object Information' pane, select 'Client'. Enter the test object information and click the 'Apply Changes' button.",
		"Click on the 'System Databases' item under the account just created in the 'Accounts' pane, then click the '+ Add Database' toolbar button.",
		"In the 'Database Information' pane enter the a URI that the client will use in it's remote database setting, choose a appropriate MIME type, then click the 'Apply Changes' button.",
		"Repeat steps 4 and 5 for all the databases on the server, which are to be tested, then click on the 'Tests' item under the account just created, double-click a test group and click on the 'Execute Test' button.",
		0,
	},
	{
		"SCTS as a Normal Server",
		"Click on '+ Account' on the toolbar or select 'Add Account' in the 'Configuration menu'. In the 'Account Information' pane enter the user name and password SCTS will use to authenticate incoming requests.",
		"Select the 'System Databases' item under the account just created in the 'Accounts' pane, then click the '+ Add Database' toolbar button or 'Add Database' in the 'Configuration menu'.",
		"In the 'Database Information' pane enter the a URI that the client will use in it's remote database setting, choose a appropriate MIME type, then click the 'Apply Changes' button.",
		"Repeat step 2 & 3 for every database the client wishes to synchronize with the server.",
		"SCTS server is ready.",
		0,
	},
	{
		"SCTS as a Normal Client",
		"Click on '+ Account' on the toolbar or select 'Add Account' in the 'Configuration menu'. In the 'Account Information' pane enter the user name and password.",
		"Select the 'System Databases' item under the account just created in the 'Accounts' pane, then click the '+ Add Database' toolbar button or 'Add Database' in the 'Configuration menu'.",
		"In the 'Database Information' pane enter the URI for the database and choose the appropriate MIME type, then click the 'Apply Changes' button. Repeat steps 2 and 3 for every database on the server, which the client was to synchronize.",
		"Select the 'Client Devices', then click on '+ Add Device' in the toolbar or 'Add Device' in the 'Configuration menu'. In the 'Device Information', enter the 'Device name', user id and password (to authenticate against the server). Select the 'Transport' type to connect to the server and enter appropriate details. Click on 'Apply Changes' button.",
		"Expand the 'Client Device' and select the 'Device Database'. 'Device Databases' have to be created for every 'System Database' the client wishes to synchronize with the server. Click on 'Add Database' in the toolbar or in the 'Configuration menu'. In the 'Target URI', enter the server's database URI and select the appropriate 'System Database'.",
		"Select the 'Client Device', and click on the 'Synchronize' button to begin synchronization session with the server.",
		0,
	}
};

CGuide::CGuide(int _guideID,CWnd* pParent /*=NULL*/)
	: CDialog(CGuide::IDD, pParent),guideID(_guideID)
{
	//{{AFX_DATA_INIT(CGuide)
	m_guide = _T("");
	//}}AFX_DATA_INIT
	step=1;
}


void CGuide::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGuide)
	DDX_Text(pDX, IDC_GUIDE, m_guide);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGuide, CDialog)
	//{{AFX_MSG_MAP(CGuide)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_BN_CLICKED(IDC_PREV, OnPrev)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGuide message handlers
void CGuide::OnNext() 
{
	++step;
	if (!guides[guideID][step])
	{
		DestroyWindow();
		return;
	}
	if (!guides[guideID][step+1]) GetDlgItem(IDC_NEXT)->SetWindowText("Finish");
	if (step==2) GetDlgItem(IDC_PREV)->EnableWindow(TRUE);
	Refresh();
}

void CGuide::OnPrev() 
{
	if (!guides[guideID][step+1]) GetDlgItem(IDC_NEXT)->SetWindowText("Next");
	--step;
	if (step==1) GetDlgItem(IDC_PREV)->EnableWindow(FALSE);
	Refresh();
}

void CGuide::Refresh()
{
	char buffer[10];
	m_guide=guides[guideID][0];
	m_guide+=" : Step ";
	m_guide+=itoa(step,buffer,10);
	m_guide+="...";
	SetWindowText(m_guide);
	m_guide=guides[guideID][step];
	UpdateData(FALSE);	
}


BOOL CGuide::OnInitDialog() 
{
	RECT rect1,rect2;
	CDialog::OnInitDialog();
	mainPane->GetWindowRect(&rect1);
	GetWindowRect(&rect2);
	MoveWindow(rect1.right-(rect2.right-rect2.left),rect1.bottom-(rect2.bottom-rect2.top),rect2.right-rect2.left,rect2.bottom-rect2.top);

	Refresh();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGuide::OnDestroy() 
{
	CDialog::OnDestroy();
	if (mainPane->activeGuide==this) mainPane->activeGuide=0;
}
