00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Network.h"
00026 #include "DiscoveryServices.h"
00027 #include "DlgDiscoveryService.h"
00028
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034
00035 BEGIN_MESSAGE_MAP(CDiscoveryServiceDlg, CSkinDialog)
00036
00037 ON_EN_CHANGE(IDC_ADDRESS, OnChangeAddress)
00038 ON_CBN_SELCHANGE(IDC_SERVICE_TYPE, OnSelChangeServiceType)
00039
00040 END_MESSAGE_MAP()
00041
00042
00044
00045
00046 CDiscoveryServiceDlg::CDiscoveryServiceDlg(CWnd* pParent, CDiscoveryService* pService) : CSkinDialog(CDiscoveryServiceDlg::IDD, pParent)
00047 {
00048
00049 m_sAddress = _T("");
00050 m_nType = -1;
00051
00052 m_pService = pService;
00053 m_bNew = FALSE;
00054 }
00055
00056 CDiscoveryServiceDlg::~CDiscoveryServiceDlg()
00057 {
00058 if ( m_pService && m_bNew ) delete m_pService;
00059 }
00060
00061 void CDiscoveryServiceDlg::DoDataExchange(CDataExchange* pDX)
00062 {
00063 CSkinDialog::DoDataExchange(pDX);
00064
00065 DDX_Control(pDX, IDOK, m_wndOK);
00066 DDX_Text(pDX, IDC_ADDRESS, m_sAddress);
00067 DDX_CBIndex(pDX, IDC_SERVICE_TYPE, m_nType);
00068
00069 }
00070
00072
00073
00074 BOOL CDiscoveryServiceDlg::OnInitDialog()
00075 {
00076 CSkinDialog::OnInitDialog();
00077
00078 SkinMe( _T("CDiscoveryServiceDlg"), IDR_DISCOVERYFRAME );
00079
00080 CSingleLock pLock( &Network.m_pSection, TRUE );
00081
00082 m_bNew = ! DiscoveryServices.Check( m_pService );
00083 if ( m_bNew ) m_pService = new CDiscoveryService();
00084
00085 m_sAddress = m_pService->m_sAddress;
00086 m_nType = m_pService->m_nType - 1;
00087
00088 if ( m_bNew ) m_nType = 1;
00089
00090 pLock.Unlock();
00091
00092 UpdateData( FALSE );
00093
00094 OnChangeAddress();
00095
00096 return TRUE;
00097 }
00098
00099 void CDiscoveryServiceDlg::OnChangeAddress()
00100 {
00101 UpdateData();
00102
00103 m_wndOK.EnableWindow( m_nType ?
00104 _tcsncmp( m_sAddress, _T("http://"), 7 ) == 0 :
00105 _tcschr( m_sAddress, '.' ) != NULL );
00106 }
00107
00108 void CDiscoveryServiceDlg::OnSelChangeServiceType()
00109 {
00110 OnChangeAddress();
00111 }
00112
00113 void CDiscoveryServiceDlg::OnOK()
00114 {
00115 UpdateData();
00116
00117 CSingleLock pLock( &Network.m_pSection, TRUE );
00118
00119 if ( ! m_bNew && ! DiscoveryServices.Check( m_pService ) )
00120 m_pService = new CDiscoveryService();
00121
00122 m_pService->m_sAddress = m_sAddress;
00123 m_pService->m_nType = m_nType + 1;
00124
00125 DiscoveryServices.Add( m_pService );
00126 m_pService = NULL;
00127
00128 pLock.Unlock();
00129
00130 CSkinDialog::OnOK();
00131 }