2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PPageWebServer.cpp : implementation file
28 #include "PPageWebServer.h"
30 // CPPageWebServer dialog
32 IMPLEMENT_DYNAMIC(CPPageWebServer
, CPPageBase
)
33 CPPageWebServer::CPPageWebServer()
34 : CPPageBase(CPPageWebServer::IDD
, CPPageWebServer::IDD
)
35 , m_fEnableWebServer(FALSE
)
37 , m_launch(_T("http://localhost:13579/"))
38 , m_fWebServerPrintDebugInfo(FALSE
)
39 , m_fWebServerUseCompression(FALSE
)
42 , m_fWebServerLocalhostOnly(FALSE
)
43 , m_WebServerCGI(_T(""))
44 , m_WebDefIndex(_T(""))
48 CPPageWebServer::~CPPageWebServer()
52 void CPPageWebServer::DoDataExchange(CDataExchange
* pDX
)
54 __super::DoDataExchange(pDX
);
55 DDX_Check(pDX
, IDC_CHECK1
, m_fEnableWebServer
);
56 DDX_Text(pDX
, IDC_EDIT1
, m_nWebServerPort
);
57 DDX_Control(pDX
, IDC_EDIT1
, m_nWebServerPortCtrl
);
58 DDX_Control(pDX
, IDC_STATIC1
, m_launch
);
59 DDX_Check(pDX
, IDC_CHECK2
, m_fWebServerPrintDebugInfo
);
60 DDX_Check(pDX
, IDC_CHECK3
, m_fWebServerUseCompression
);
61 DDX_Check(pDX
, IDC_CHECK4
, m_fWebRoot
);
62 DDX_Text(pDX
, IDC_EDIT2
, m_WebRoot
);
63 DDX_Check(pDX
, IDC_CHECK5
, m_fWebServerLocalhostOnly
);
64 DDX_Text(pDX
, IDC_EDIT3
, m_WebServerCGI
);
65 DDX_Text(pDX
, IDC_EDIT9
, m_WebDefIndex
);
68 BOOL
CPPageWebServer::PreTranslateMessage(MSG
* pMsg
)
70 if(pMsg
->message
== WM_LBUTTONDOWN
&& pMsg
->hwnd
== m_launch
.m_hWnd
)
74 AppSettings
& s
= AfxGetAppSettings();
76 if(CMainFrame
* pWnd
= (CMainFrame
*)AfxGetMainWnd())
78 if(m_fEnableWebServer
)
80 if(s
.nWebServerPort
!= m_nWebServerPort
)
82 AfxMessageBox(_T("Press apply first, before testing the new settings!"), MB_OK
);
89 return CPPageBase::PreTranslateMessage(pMsg
);
92 BOOL
CPPageWebServer::OnInitDialog()
94 __super::OnInitDialog();
96 AppSettings
& s
= AfxGetAppSettings();
98 m_fEnableWebServer
= s
.fEnableWebServer
;
99 m_nWebServerPort
= s
.nWebServerPort
;
100 m_fWebServerPrintDebugInfo
= s
.fWebServerPrintDebugInfo
;
101 m_fWebServerLocalhostOnly
= s
.fWebServerLocalhostOnly
;
102 m_fWebServerUseCompression
= s
.fWebServerUseCompression
;
103 m_fWebRoot
= s
.WebRoot
.Find('*') < 0;
104 m_WebRoot
= s
.WebRoot
;
105 m_WebRoot
.TrimLeft(_T("*"));
106 m_WebDefIndex
= s
.WebDefIndex
;
107 m_WebServerCGI
= s
.WebServerCGI
;
113 return TRUE
; // return TRUE unless you set the focus to a control
114 // EXCEPTION: OCX Property Pages should return FALSE
117 BOOL
CPPageWebServer::OnApply()
121 AppSettings
& s
= AfxGetAppSettings();
123 CString NewWebRoot
= m_WebRoot
;
124 if(!m_fWebRoot
) NewWebRoot
= _T("*") + NewWebRoot
;
126 bool fRestart
= s
.nWebServerPort
!= m_nWebServerPort
127 || s
.WebRoot
!= NewWebRoot
|| s
.WebServerCGI
!= m_WebServerCGI
;
129 s
.fEnableWebServer
= !!m_fEnableWebServer
;
130 s
.nWebServerPort
= m_nWebServerPort
;
131 s
.fWebServerPrintDebugInfo
= !!m_fWebServerPrintDebugInfo
;
132 s
.fWebServerLocalhostOnly
= !!m_fWebServerLocalhostOnly
;
133 s
.fWebServerUseCompression
= !!m_fWebServerUseCompression
;
134 s
.WebRoot
= NewWebRoot
;
135 s
.WebDefIndex
= m_WebDefIndex
;
136 s
.WebServerCGI
= m_WebServerCGI
;
138 if(CMainFrame
* pWnd
= (CMainFrame
*)AfxGetMainWnd())
140 if(m_fEnableWebServer
)
142 if(fRestart
) pWnd
->StopWebServer();
143 pWnd
->StartWebServer(m_nWebServerPort
);
147 pWnd
->StopWebServer();
151 return __super::OnApply();
154 CString
CPPageWebServer::GetMPCDir()
157 GetModuleFileName(AfxGetInstanceHandle(), dir
.GetBuffer(MAX_PATH
), MAX_PATH
);
160 path
.RemoveFileSpec();
161 return (LPCTSTR
)path
;
164 CString
CPPageWebServer::GetCurWebRoot()
167 GetDlgItem(IDC_EDIT2
)->GetWindowText(WebRoot
);
168 WebRoot
.Replace('/', '\\');
171 path
.Combine(GetMPCDir(), WebRoot
);
172 return path
.IsDirectory() ? (LPCTSTR
)path
: _T("");
175 static int __stdcall
BrowseCtrlCallback(HWND hwnd
, UINT uMsg
, LPARAM lParam
, LPARAM lpData
)
177 if(uMsg
== BFFM_INITIALIZED
&& lpData
)
178 ::SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, lpData
);
182 bool CPPageWebServer::PickDir(CString
& dir
)
184 TCHAR buff
[MAX_PATH
];
187 bi
.hwndOwner
= m_hWnd
;
189 bi
.pszDisplayName
= buff
;
190 bi
.lpszTitle
= _T("Select the directory");
191 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_VALIDATE
| BIF_USENEWUI
;
192 bi
.lpfn
= BrowseCtrlCallback
;
193 bi
.lParam
= (LPARAM
)(LPCTSTR
)dir
;
197 if(iil
= SHBrowseForFolder(&bi
))
199 SHGetPathFromIDList(iil
, buff
);
207 BEGIN_MESSAGE_MAP(CPPageWebServer
, CPPageBase
)
208 ON_EN_CHANGE(IDC_EDIT1
, OnEnChangeEdit1
)
209 ON_BN_CLICKED(IDC_BUTTON1
, OnBnClickedButton1
)
210 ON_BN_CLICKED(IDC_BUTTON2
, OnBnClickedButton2
)
211 ON_UPDATE_COMMAND_UI(IDC_BUTTON1
, OnUpdateButton2
)
215 // CPPageWebServer message handlers
218 void CPPageWebServer::OnEnChangeEdit1()
223 link
.Format(_T("http://localhost:%d/"), m_nWebServerPort
);
224 m_launch
.m_link
= link
;
229 void CPPageWebServer::OnBnClickedButton1()
231 CString dir
= GetCurWebRoot();
235 if(path
.RelativePathTo(GetMPCDir(), FILE_ATTRIBUTE_DIRECTORY
, dir
, FILE_ATTRIBUTE_DIRECTORY
))
242 void CPPageWebServer::OnBnClickedButton2()
248 CWebServer::Deploy(dir
);
252 void CPPageWebServer::OnUpdateButton2(CCmdUI
* pCmdUI
)
254 pCmdUI
->Enable(GetDlgItem(IDC_EDIT2
)->GetWindowTextLength() > 0);