X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / PPageWebServer.cpp
blob650d578a78b69ef8b4a7c6ab12764fd32e843169
1 /*
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)
8 * any later version.
9 *
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
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "MainFrm.h"
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)
36 , m_nWebServerPort(0)
37 , m_launch(_T("http://localhost:13579/"))
38 , m_fWebServerPrintDebugInfo(FALSE)
39 , m_fWebServerUseCompression(FALSE)
40 , m_fWebRoot(FALSE)
41 , m_WebRoot(_T(""))
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)
72 UpdateData();
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);
83 return TRUE;
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;
109 UpdateData(FALSE);
111 OnEnChangeEdit1();
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()
119 UpdateData();
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);
145 else
147 pWnd->StopWebServer();
151 return __super::OnApply();
154 CString CPPageWebServer::GetMPCDir()
156 CString dir;
157 GetModuleFileName(AfxGetInstanceHandle(), dir.GetBuffer(MAX_PATH), MAX_PATH);
158 dir.ReleaseBuffer();
159 CPath path(dir);
160 path.RemoveFileSpec();
161 return (LPCTSTR)path;
164 CString CPPageWebServer::GetCurWebRoot()
166 CString WebRoot;
167 GetDlgItem(IDC_EDIT2)->GetWindowText(WebRoot);
168 WebRoot.Replace('/', '\\');
170 CPath path;
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);
179 return 0;
182 bool CPPageWebServer::PickDir(CString& dir)
184 TCHAR buff[MAX_PATH];
186 BROWSEINFO bi;
187 bi.hwndOwner = m_hWnd;
188 bi.pidlRoot = NULL;
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;
194 bi.iImage = 0;
196 LPITEMIDLIST iil;
197 if(iil = SHBrowseForFolder(&bi))
199 SHGetPathFromIDList(iil, buff);
200 dir = buff;
201 return true;
204 return false;
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)
212 END_MESSAGE_MAP()
215 // CPPageWebServer message handlers
218 void CPPageWebServer::OnEnChangeEdit1()
220 UpdateData();
222 CString link;
223 link.Format(_T("http://localhost:%d/"), m_nWebServerPort);
224 m_launch.m_link = link;
226 SetModified();
229 void CPPageWebServer::OnBnClickedButton1()
231 CString dir = GetCurWebRoot();
232 if(PickDir(dir))
234 CPath path;
235 if(path.RelativePathTo(GetMPCDir(), FILE_ATTRIBUTE_DIRECTORY, dir, FILE_ATTRIBUTE_DIRECTORY))
236 dir = (LPCTSTR)path;
237 m_WebRoot = dir;
238 UpdateData(FALSE);
242 void CPPageWebServer::OnBnClickedButton2()
244 CString dir;
245 if(PickDir(dir))
247 dir += _T("\\");
248 CWebServer::Deploy(dir);
252 void CPPageWebServer::OnUpdateButton2(CCmdUI* pCmdUI)
254 pCmdUI->Enable(GetDlgItem(IDC_EDIT2)->GetWindowTextLength() > 0);