//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "emuleDlg.h"
#include "PPgAckronicIII.h"
#include "OtherFunctions.h"
#include "Preferences.h"
#include "Opcodes.h"
#include "ServerWnd.h"//Ackronic - AcKroNiC/EneTec Servers Filter

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


IMPLEMENT_DYNAMIC(CPPgAckronicIII, CPropertyPage)

BEGIN_MESSAGE_MAP(CPPgAckronicIII, CPropertyPage)
	//Ackronic START - AcKroNiC/EneTec Servers Filter
	ON_EN_CHANGE(IDC_FILTERNAME, OnSettingsChange)
	ON_EN_CHANGE(IDC_FILTERDESC, OnSettingsChange)
	ON_EN_CHANGE(IDC_FILTERUSERVAL, OnSettingsChange)
	ON_EN_CHANGE(IDC_FILTERFILEVAL, OnSettingsChange)
	ON_BN_CLICKED(IDC_FILTERSERVERBYIPFILTER , OnSettingsChange)
	ON_BN_CLICKED(IDC_STATIC,OnBnClickedAckHelp)
	//Ackronic END - AcKroNiC/EneTec Servers Filter
	//Ackronic START - Links
	ON_BN_CLICKED(IDC_ACKHELP,OnBnClickedAckHelp)
	ON_BN_CLICKED(IDC_ACKHELP3,OnBnClickedAckHelp3)
	//Ackronic END - Links
	//ON_WM_HELPINFO()
	ON_WM_HSCROLL()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

CPPgAckronicIII::CPPgAckronicIII()
	: CPropertyPage(CPPgAckronicIII::IDD)
{
}

CPPgAckronicIII::~CPPgAckronicIII()
{
}

void CPPgAckronicIII::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
}

BOOL CPPgAckronicIII::OnInitDialog()
{
	CPropertyPage::OnInitDialog();
	InitWindowStyles(this);


	LoadSettings();
	Localize();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}
void CPPgAckronicIII::LoadSettings(void)
{
	//Ackronic START: AcKroNiC/EneTec Servers Filter
	GetDlgItem(IDC_FILTERNAME)->SetWindowText(thePrefs.ServerFilterVal);
	GetDlgItem(IDC_FILTERDESC)->SetWindowText(thePrefs.ServerFilterDesc);
	SetDlgItemInt(IDC_FILTERUSERVAL, thePrefs.ServerFilterByUsers, FALSE);
	SetDlgItemInt(IDC_FILTERFILEVAL, thePrefs.ServerFilterByFiles, FALSE);
	if(thePrefs.filterserverbyip)
		CheckDlgButton(IDC_FILTERSERVERBYIPFILTER,1);
	else
		CheckDlgButton(IDC_FILTERSERVERBYIPFILTER,0);
	//Ackronic END: AcKroNiC/EneTec Servers Filter
}

BOOL CPPgAckronicIII::OnApply()
{
	if (!UpdateData())
		return FALSE;

	//Ackronic START - AcKroNiC/EneTec Servers Filter
	GetDlgItem(IDC_FILTERNAME)->GetWindowText(thePrefs.ServerFilterVal,ARRSIZE(thePrefs.ServerFilterVal));
	GetDlgItem(IDC_FILTERDESC)->GetWindowText(thePrefs.ServerFilterDesc,ARRSIZE(thePrefs.ServerFilterDesc));

	thePrefs.ServerFilterByUsers = GetDlgItemInt(IDC_FILTERUSERVAL, NULL, FALSE);
	if (thePrefs.ServerFilterByUsers < 0)
		thePrefs.ServerFilterByUsers = 0;
	else if (thePrefs.ServerFilterByUsers > 1000000000)
		thePrefs.ServerFilterByUsers = 1000000000;

	thePrefs.ServerFilterByFiles = GetDlgItemInt(IDC_FILTERFILEVAL, NULL, FALSE);
	if (thePrefs.ServerFilterByFiles < 0)
		thePrefs.ServerFilterByFiles = 0;
	else if (thePrefs.ServerFilterByFiles > 1000000000)
		thePrefs.ServerFilterByFiles = 1000000000;

	thePrefs.filterserverbyip = IsDlgButtonChecked(IDC_FILTERSERVERBYIPFILTER)!=0;
	
	if(thePrefs.filterserverbyip)
	theApp.emuledlg->serverwnd->OnBnClickedServerFilterDlg();
	
	theApp.emuledlg->serverwnd->GetDlgItem(IDC_SRVFILTER_BTN)->EnableWindow(thePrefs.filterserverbyip);
	//Ackronic END - AcKroNiC/EneTec Servers Filter

	LoadSettings();
	SetModified(FALSE);
	return CPropertyPage::OnApply();
}

void CPPgAckronicIII::Localize(void)
{
	if (m_hWnd)
	{

		//Ackronic START - Links
		GetDlgItem(IDC_ACKHELP)->SetWindowText(GetResString(IDS_ACKHELP));
		GetDlgItem(IDC_ACKHELP3)->SetWindowText(GetResString(IDS_ACKHELP3));
		//Ackronic END - Links
		//Ackronic START - AcKroNiC/EneTec Servers Filter
		GetDlgItem(IDC_FILTERNAMELABEL)->SetWindowText(GetResString(IDS_FILTERNAMELABEL));
		GetDlgItem(IDC_FILTERDESCLABEL)->SetWindowText(GetResString(IDS_FILTERDESCLABEL));
		GetDlgItem(IDC_FILTERUSER)->SetWindowText(GetResString(IDS_FILTERUSERS_DESC));
		GetDlgItem(IDC_FILTERUSER2)->SetWindowText(GetResString(IDS_LUSERS));
		GetDlgItem(IDC_FILTERFILE)->SetWindowText(GetResString(IDS_FILTERUSERS_DESC));
		GetDlgItem(IDC_FILTERFILE2)->SetWindowText(GetResString(IDS_FILES));
		GetDlgItem(IDC_FILTERSERVERBYIPFILTER)->SetWindowText(GetResString(IDS_FILTERSERVERBYIPFILTER));
		//Ackronic END - AcKroNiC/EneTec Servers Filter

	
	}
}
//Ackronic START - Links
void CPPgAckronicIII::OnBnClickedAckHelp()
{
TCHAR link[64];
_tcscpy (link, _T("http://www.ackronic.net/ackws/guida/helpack4.html"));
ShellExecute(NULL, NULL, link, NULL, thePrefs.GetAppDir(), SW_SHOWDEFAULT);
}
void CPPgAckronicIII::OnBnClickedAckHelp3()
{
TCHAR link[64];
_tcscpy (link, _T("http://www.emulesecurity.net/"));
ShellExecute(NULL, NULL, link, NULL, thePrefs.GetAppDir(), SW_SHOWDEFAULT);
}
//Ackronic END - Links