replace own balloon implementation with mfc one
[TortoiseGit.git] / src / TortoiseProc / Settings / SetProxyPage.cpp
blob9a157b4760e43b2203c8e07ad11bcfcfc28a4347
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
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 this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "SetProxyPage.h"
22 #include "AppUtils.h"
23 #include "StringUtils.h"
24 #include "git.h"
25 #include ".\setproxypage.h"
26 #include "MessageBox.h"
28 IMPLEMENT_DYNAMIC(CSetProxyPage, ISettingsPropPage)
29 CSetProxyPage::CSetProxyPage()
30 : ISettingsPropPage(CSetProxyPage::IDD)
31 , m_serveraddress(_T(""))
32 , m_serverport(0)
33 , m_username(_T(""))
34 , m_password(_T(""))
35 , m_isEnabled(FALSE)
36 , m_SSHClient(_T(""))
38 m_regServeraddress = CRegString(_T("Software\\TortoiseGit\\Git\\Servers\\global\\http-proxy-host"), _T(""));
39 m_regServerport = CRegString(_T("Software\\TortoiseGit\\Git\\Servers\\global\\http-proxy-port"), _T(""));
40 m_regUsername = CRegString(_T("Software\\TortoiseGit\\Git\\Servers\\global\\http-proxy-username"), _T(""));
41 m_regPassword = CRegString(_T("Software\\TortoiseGit\\Git\\Servers\\global\\http-proxy-password"), _T(""));
42 m_regSSHClient = CRegString(_T("Software\\TortoiseGit\\SSH"));
43 m_SSHClient = m_regSSHClient;
47 CSetProxyPage::~CSetProxyPage()
51 void CSetProxyPage::DoDataExchange(CDataExchange* pDX)
53 ISettingsPropPage::DoDataExchange(pDX);
54 DDX_Text(pDX, IDC_SERVERADDRESS, m_serveraddress);
55 DDX_Text(pDX, IDC_SERVERPORT, m_serverport);
56 DDX_Text(pDX, IDC_USERNAME, m_username);
57 DDX_Text(pDX, IDC_PASSWORD, m_password);
58 DDX_Check(pDX, IDC_ENABLE, m_isEnabled);
59 DDX_Text(pDX, IDC_SSHCLIENT, m_SSHClient);
60 DDX_Control(pDX, IDC_SSHCLIENT, m_cSSHClientEdit);
64 BEGIN_MESSAGE_MAP(CSetProxyPage, ISettingsPropPage)
65 ON_EN_CHANGE(IDC_SERVERADDRESS, OnChange)
66 ON_EN_CHANGE(IDC_SERVERPORT, OnChange)
67 ON_EN_CHANGE(IDC_USERNAME, OnChange)
68 ON_EN_CHANGE(IDC_PASSWORD, OnChange)
69 ON_EN_CHANGE(IDC_TIMEOUT, OnChange)
70 ON_EN_CHANGE(IDC_SSHCLIENT, OnChange)
71 ON_EN_CHANGE(IDC_EXCEPTIONS, OnChange)
72 ON_BN_CLICKED(IDC_ENABLE, OnBnClickedEnable)
73 ON_BN_CLICKED(IDC_SSHBROWSE, OnBnClickedSshbrowse)
74 END_MESSAGE_MAP()
78 BOOL CSetProxyPage::OnInitDialog()
80 ISettingsPropPage::OnInitDialog();
82 m_tooltips.Create(this);
83 m_tooltips.AddTool(IDC_SERVERADDRESS, IDS_SETTINGS_PROXYSERVER_TT);
85 CString proxy=g_Git.GetConfigValue(_T("http.proxy"),CP_ACP);
87 m_SSHClient = m_regSSHClient;
88 m_serveraddress = m_regServeraddress;
89 m_serverport = _ttoi((LPCTSTR)(CString)m_regServerport);
90 m_username = m_regUsername;
91 m_password = m_regPassword;
93 if (proxy.IsEmpty())
95 m_isEnabled = FALSE;
96 EnableGroup(FALSE);
98 else
100 int start=0;
101 start = proxy.Find(_T("://"),start);
102 if(start<0)
103 start =0;
104 else
105 start+=3;
107 int at = proxy.Find(_T("@"), 0);
108 int port;
110 if(at<0)
112 m_username=_T("");
113 m_password=_T("");
114 port=proxy.Find(_T(":"),start);
115 if(port<0)
116 m_serveraddress = proxy.Mid(start);
117 else
118 m_serveraddress = proxy.Mid(start, port-start);
121 else
123 int username;
124 username = proxy.Find(_T(":"),start);
125 if(username<=0 || username >at)
127 m_username=proxy.Mid(start, at-start);
128 m_password=_T("");
130 else if(username < at)
132 m_username=proxy.Mid(start, username-start);
133 m_password=proxy.Mid(username+1,at - username-1);
136 port=proxy.Find(_T(":"),at);
137 if(port<0)
138 m_serveraddress = proxy.Mid(at+1);
139 else
140 m_serveraddress = proxy.Mid(at+1, port-at-1);
143 if(port<0)
145 m_serverport= 0;
147 else
148 m_serverport = _ttoi(proxy.Mid(port+1));
150 m_isEnabled = TRUE;
151 EnableGroup(TRUE);
154 SHAutoComplete(::GetDlgItem(m_hWnd, IDC_SSHCLIENT), SHACF_FILESYSTEM | SHACF_FILESYS_ONLY);
156 UpdateData(FALSE);
158 return TRUE;
161 void CSetProxyPage::OnBnClickedEnable()
163 UpdateData();
164 if (m_isEnabled)
166 EnableGroup(TRUE);
168 else
170 EnableGroup(FALSE);
172 SetModified();
175 void CSetProxyPage::EnableGroup(BOOL b)
177 GetDlgItem(IDC_SERVERADDRESS)->EnableWindow(b);
178 GetDlgItem(IDC_SERVERPORT)->EnableWindow(b);
179 GetDlgItem(IDC_USERNAME)->EnableWindow(b);
180 GetDlgItem(IDC_PASSWORD)->EnableWindow(b);
181 GetDlgItem(IDC_PROXYLABEL1)->EnableWindow(b);
182 GetDlgItem(IDC_PROXYLABEL2)->EnableWindow(b);
183 GetDlgItem(IDC_PROXYLABEL3)->EnableWindow(b);
184 GetDlgItem(IDC_PROXYLABEL6)->EnableWindow(b);
187 BOOL CSetProxyPage::PreTranslateMessage(MSG* pMsg)
189 m_tooltips.RelayEvent(pMsg);
190 return ISettingsPropPage::PreTranslateMessage(pMsg);
193 void CSetProxyPage::OnChange()
195 SetModified();
198 BOOL CSetProxyPage::OnApply()
200 UpdateData();
202 CString temp;
203 Store (m_serveraddress, m_regServeraddress);
204 temp.Format(_T("%d"), m_serverport);
205 Store (temp, m_regServerport);
206 Store (m_username, m_regUsername);
207 Store (m_password, m_regPassword);
210 CString http_proxy;
211 if(!m_serveraddress.IsEmpty())
213 if(m_serveraddress.Left(5) != _T("http:"))
214 http_proxy=_T("http://");
217 if(!m_username.IsEmpty())
219 http_proxy += m_username;
221 if(!m_password.IsEmpty())
222 http_proxy += _T(":")+m_password;
224 http_proxy += _T("@");
228 http_proxy+=m_serveraddress;
230 if(m_serverport)
232 temp.Format(_T("%d"), m_serverport);
233 http_proxy += _T(":")+temp;
237 if (m_isEnabled)
239 g_Git.SetConfigValue(_T("http.proxy"),http_proxy,CONFIG_GLOBAL);
241 else
243 g_Git.SetConfigValue(_T("http.proxy"),_T(""),CONFIG_GLOBAL);
245 m_regSSHClient = m_SSHClient;
246 SetModified(FALSE);
247 return ISettingsPropPage::OnApply();
251 void CSetProxyPage::OnBnClickedSshbrowse()
253 CString openPath;
254 if (CAppUtils::FileOpenSave(openPath, NULL, IDS_SETTINGS_SELECTSSH, IDS_PROGRAMSFILEFILTER, true, m_hWnd))
256 UpdateData();
257 m_SSHClient = openPath;
258 UpdateData(FALSE);
259 SetModified();