git fetch show progress
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsBugtraqConfig.cpp
blob9af264973ff746e818fc1e74fb073a7a2c83a518
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014 - TortoiseGit
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 // settings\SettingsBugtraqConfig.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SettingsBugtraqConfig.h"
25 #include "ProjectProperties.h"
26 #include "Git.h"
27 #include "BugtraqRegexTestDlg.h"
28 #include "BugTraqAssociations.h"
30 // CSettingsBugtraqConfig dialog
32 IMPLEMENT_DYNAMIC(CSettingsBugtraqConfig, ISettingsPropPage)
34 CSettingsBugtraqConfig::CSettingsBugtraqConfig(CString cmdPath)
35 : ISettingsPropPage(CSettingsBugtraqConfig::IDD)
36 , m_bNeedSave(false)
37 , m_bInheritURL(FALSE)
38 , m_bInheritMessage(FALSE)
39 , m_bInheritLabel(FALSE)
40 , m_bInheritLogregex(FALSE)
41 , m_bInheritUUID32(FALSE)
42 , m_bInheritUUID64(FALSE)
43 , m_bInheritParams(FALSE)
47 CSettingsBugtraqConfig::~CSettingsBugtraqConfig()
51 void CSettingsBugtraqConfig::DoDataExchange(CDataExchange* pDX)
53 CPropertyPage::DoDataExchange(pDX);
54 DDX_Text(pDX, IDC_BUGTRAQ_URL, m_URL);
55 DDX_Control(pDX, IDC_BUGTRAQ_WARNINGIFNOISSUE, m_cWarningifnoissue);
56 DDX_Text(pDX, IDC_BUGTRAQ_MESSAGE, m_Message);
57 DDX_Control(pDX, IDC_BUGTRAQ_APPEND, m_cAppend);
58 DDX_Text(pDX, IDC_BUGTRAQ_LABEL, m_Label);
59 DDX_Control(pDX, IDC_BUGTRAQ_NUMBER, m_cNumber);
60 DDX_Text(pDX, IDC_BUGTRAQ_LOGREGEX, m_Logregex);
61 DDX_Control(pDX, IDC_BUGTRAQ_LOGREGEX, m_BugtraqRegex1);
62 DDX_Check(pDX, IDC_CHECK_INHERIT_BTURL, m_bInheritURL);
63 DDX_Check(pDX, IDC_CHECK_INHERIT_BTMSG, m_bInheritMessage);
64 DDX_Check(pDX, IDC_CHECK_INHERIT_BTLABEL, m_bInheritLabel);
65 DDX_Check(pDX, IDC_CHECK_INHERIT_BTREGEXP, m_bInheritLogregex);
66 DDX_Check(pDX, IDC_CHECK_INHERIT_BTUUID32, m_bInheritUUID32);
67 DDX_Check(pDX, IDC_CHECK_INHERIT_BTUUID64, m_bInheritUUID64);
68 DDX_Check(pDX, IDC_CHECK_INHERIT_BTPARAMS, m_bInheritParams);
69 DDX_Text(pDX, IDC_UUID32, m_UUID32);
70 DDX_Text(pDX, IDC_UUID64, m_UUID64);
71 DDX_Text(pDX, IDC_PARAMS, m_Params);
72 GITSETTINGS_DDX
75 BEGIN_MESSAGE_MAP(CSettingsBugtraqConfig, ISettingsPropPage)
76 GITSETTINGS_RADIO_EVENT
77 ON_EN_CHANGE(IDC_BUGTRAQ_URL, &CSettingsBugtraqConfig::OnChange)
78 ON_CBN_SELCHANGE(IDC_BUGTRAQ_WARNINGIFNOISSUE, &CSettingsBugtraqConfig::OnChange)
79 ON_EN_CHANGE(IDC_BUGTRAQ_MESSAGE, &CSettingsBugtraqConfig::OnChange)
80 ON_CBN_SELCHANGE(IDC_BUGTRAQ_APPEND, &CSettingsBugtraqConfig::OnChange)
81 ON_EN_CHANGE(IDC_BUGTRAQ_LABEL, &CSettingsBugtraqConfig::OnChange)
82 ON_CBN_SELCHANGE(IDC_BUGTRAQ_NUMBER, &CSettingsBugtraqConfig::OnChange)
83 ON_EN_CHANGE(IDC_BUGTRAQ_LOGREGEX, &CSettingsBugtraqConfig::OnChange)
84 ON_EN_CHANGE(IDC_UUID32, &CSettingsBugtraqConfig::OnChange)
85 ON_EN_CHANGE(IDC_UUID64, &CSettingsBugtraqConfig::OnChange)
86 ON_EN_CHANGE(IDC_PARAMS, &CSettingsBugtraqConfig::OnChange)
87 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTURL, &OnChange)
88 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTMSG, &OnChange)
89 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTLABEL, &OnChange)
90 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTREGEXP, &OnChange)
91 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTUUID32, &OnChange)
92 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTUUID64, &OnChange)
93 ON_BN_CLICKED(IDC_CHECK_INHERIT_BTPARAMS, &OnChange)
94 ON_BN_CLICKED(IDC_TESTBUGTRAQREGEXBUTTON, &CSettingsBugtraqConfig::OnBnClickedTestbugtraqregexbutton)
95 END_MESSAGE_MAP()
97 BOOL CSettingsBugtraqConfig::OnInitDialog()
99 ISettingsPropPage::OnInitDialog();
101 AddTrueFalseToComboBox(m_cWarningifnoissue);
102 AddTrueFalseToComboBox(m_cAppend);
103 AddTrueFalseToComboBox(m_cNumber);
105 m_tooltips.Create(this);
107 InitGitSettings(this, true, &m_tooltips);
109 this->UpdateData(FALSE);
110 return TRUE;
113 void CSettingsBugtraqConfig::EnDisableControls()
115 GetDlgItem(IDC_BUGTRAQ_URL)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
116 GetDlgItem(IDC_BUGTRAQ_MESSAGE)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
117 GetDlgItem(IDC_BUGTRAQ_LABEL)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
118 GetDlgItem(IDC_BUGTRAQ_LOGREGEX)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
119 GetDlgItem(IDC_UUID32)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
120 GetDlgItem(IDC_UUID64)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
121 GetDlgItem(IDC_PARAMS)->SendMessage(EM_SETREADONLY, m_iConfigSource == 0, 0);
123 GetDlgItem(IDC_BUGTRAQ_WARNINGIFNOISSUE)->EnableWindow(m_iConfigSource != 0);
124 GetDlgItem(IDC_BUGTRAQ_APPEND)->EnableWindow(m_iConfigSource != 0);
125 GetDlgItem(IDC_BUGTRAQ_NUMBER)->EnableWindow(m_iConfigSource != 0);
126 GetDlgItem(IDC_COMBO_SETTINGS_SAFETO)->EnableWindow(m_iConfigSource != 0);
127 GetDlgItem(IDC_CHECK_INHERIT_BTURL)->EnableWindow(m_iConfigSource != 0);
128 GetDlgItem(IDC_CHECK_INHERIT_BTMSG)->EnableWindow(m_iConfigSource != 0);
129 GetDlgItem(IDC_CHECK_INHERIT_BTLABEL)->EnableWindow(m_iConfigSource != 0);
130 GetDlgItem(IDC_CHECK_INHERIT_BTREGEXP)->EnableWindow(m_iConfigSource != 0);
131 GetDlgItem(IDC_CHECK_INHERIT_BTUUID32)->EnableWindow(m_iConfigSource != 0);
132 GetDlgItem(IDC_CHECK_INHERIT_BTUUID64)->EnableWindow(m_iConfigSource != 0);
133 GetDlgItem(IDC_CHECK_INHERIT_BTPARAMS)->EnableWindow(m_iConfigSource != 0);
134 GetDlgItem(IDC_TESTBUGTRAQREGEXBUTTON)->EnableWindow(m_iConfigSource != 0 && !m_bInheritLogregex);
136 GetDlgItem(IDC_BUGTRAQ_URL)->EnableWindow(!m_bInheritURL);
137 GetDlgItem(IDC_BUGTRAQ_MESSAGE)->EnableWindow(!m_bInheritMessage);
138 GetDlgItem(IDC_BUGTRAQ_LABEL)->EnableWindow(!m_bInheritLabel);
139 GetDlgItem(IDC_BUGTRAQ_LOGREGEX)->EnableWindow(!m_bInheritLogregex);
140 GetDlgItem(IDC_UUID32)->EnableWindow(!m_bInheritUUID32);
141 GetDlgItem(IDC_UUID64)->EnableWindow(!m_bInheritUUID64);
142 GetDlgItem(IDC_PARAMS)->EnableWindow(!m_bInheritParams);
143 UpdateData(FALSE);
146 void CSettingsBugtraqConfig::OnChange()
148 UpdateData();
149 EnDisableControls();
150 m_bNeedSave = true;
151 SetModified();
154 void CSettingsBugtraqConfig::LoadDataImpl(CAutoConfig& config)
156 if (m_iConfigSource == 0)
158 // use project properties here, so that we correctly get the default values
159 ProjectProperties props;
160 props.ReadProps();
161 m_URL = props.sUrl;
162 m_Logregex = props.sCheckRe + _T("\n") + props.sBugIDRe;
163 m_Label = props.sLabel;
164 m_Message = props.sMessage;
165 m_UUID32 = props.sProviderUuid;
166 m_UUID64 = props.sProviderUuid64;
167 m_Params = props.sProviderParams;
168 // read legacy registry values
169 CBugTraqAssociations bugtraq_associations;
170 bugtraq_associations.Load(props.GetProviderUUID(), props.sProviderParams);
171 CBugTraqAssociation bugtraq_association;
172 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &bugtraq_association))
174 #if _WIN64
175 m_UUID64 = bugtraq_association.GetProviderClassAsString();
176 #else
177 m_UUID32 = bugtraq_association.GetProviderClassAsString();
178 if (m_UUID64.IsEmpty())
179 m_UUID64 = m_UUID32;
180 #endif
181 m_Params = bugtraq_association.GetParameters();
184 if (props.bAppend)
185 m_cAppend.SetCurSel(1);
186 else
187 m_cAppend.SetCurSel(2);
189 if (props.bNumber)
190 m_cNumber.SetCurSel(1);
191 else
192 m_cNumber.SetCurSel(2);
194 if (props.bWarnIfNoIssue)
195 m_cWarningifnoissue.SetCurSel(1);
196 else
197 m_cWarningifnoissue.SetCurSel(2);
199 m_bInheritURL = FALSE;
200 m_bInheritMessage = FALSE;
201 m_bInheritLabel = FALSE;
202 m_bInheritLogregex = FALSE;
203 m_bInheritParams = FALSE;
204 m_bInheritUUID32 = FALSE;
205 m_bInheritUUID64 = FALSE;
207 else
209 m_bInheritURL = (config.GetString(BUGTRAQPROPNAME_URL, m_URL) == GIT_ENOTFOUND);
210 m_bInheritMessage = (config.GetString(BUGTRAQPROPNAME_MESSAGE, m_Message) == GIT_ENOTFOUND);
211 m_bInheritLabel = (config.GetString(BUGTRAQPROPNAME_LABEL, m_Label) == GIT_ENOTFOUND);
212 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_NUMBER, m_cNumber);
213 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_APPEND, m_cAppend);
214 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_WARNIFNOISSUE, m_cWarningifnoissue);
215 m_bInheritLogregex = (config.GetString(BUGTRAQPROPNAME_LOGREGEX, m_Logregex) == GIT_ENOTFOUND);
216 m_bInheritParams = (config.GetString(BUGTRAQPROPNAME_PROVIDERPARAMS, m_Params) == GIT_ENOTFOUND);
217 m_bInheritUUID32 = (config.GetString(BUGTRAQPROPNAME_PROVIDERUUID, m_UUID32) == GIT_ENOTFOUND);
218 m_bInheritUUID64 = (config.GetString(BUGTRAQPROPNAME_PROVIDERUUID64, m_UUID64) == GIT_ENOTFOUND);
221 m_Logregex.Trim();
222 m_Logregex.Replace(_T("\n"), _T("\r\n"));
224 m_bNeedSave = false;
225 SetModified(FALSE);
226 UpdateData(FALSE);
229 BOOL CSettingsBugtraqConfig::SafeDataImpl(CAutoConfig& config)
231 if (!Save(config, BUGTRAQPROPNAME_URL, m_URL, m_bInheritURL == TRUE))
232 return FALSE;
234 if (!Save(config, BUGTRAQPROPNAME_MESSAGE, m_Message, m_bInheritMessage == TRUE))
235 return FALSE;
237 if (!Save(config, BUGTRAQPROPNAME_LABEL, m_Label, m_bInheritLabel == TRUE))
238 return FALSE;
240 if (!Save(config, BUGTRAQPROPNAME_PROVIDERPARAMS, m_Params, m_bInheritParams == TRUE))
241 return FALSE;
243 if (!Save(config, BUGTRAQPROPNAME_PROVIDERUUID, m_UUID32, m_bInheritUUID32 == TRUE))
244 return FALSE;
246 if (!Save(config, BUGTRAQPROPNAME_PROVIDERUUID64, m_UUID64, m_bInheritUUID64 == TRUE))
247 return FALSE;
250 CString value;
251 m_cAppend.GetWindowText(value);
252 if (!Save(config, BUGTRAQPROPNAME_APPEND, value, value.IsEmpty()))
253 return FALSE;
256 CString value;
257 m_cNumber.GetWindowText(value);
258 if (!Save(config, BUGTRAQPROPNAME_NUMBER, value, value.IsEmpty()))
259 return FALSE;
262 CString value;
263 m_cWarningifnoissue.GetWindowText(value);
264 if (!Save(config, BUGTRAQPROPNAME_WARNIFNOISSUE, value, value.IsEmpty()))
265 return FALSE;
268 CString value(m_Logregex);
269 value.Replace(_T("\r\n"),_T("\n"));
270 if (!Save(config, BUGTRAQPROPNAME_LOGREGEX, value, m_bInheritLogregex == TRUE))
271 return FALSE;
274 return TRUE;
277 BOOL CSettingsBugtraqConfig::OnApply()
279 if (!m_bNeedSave)
280 return TRUE;
281 UpdateData();
282 if (!SafeData())
283 return FALSE;
284 m_bNeedSave = false;
285 SetModified(FALSE);
286 return TRUE;
289 BOOL CSettingsBugtraqConfig::PreTranslateMessage(MSG* pMsg)
291 m_tooltips.RelayEvent(pMsg);
292 return ISettingsPropPage::PreTranslateMessage(pMsg);
295 void CSettingsBugtraqConfig::OnBnClickedTestbugtraqregexbutton()
297 m_tooltips.Pop(); // hide the tooltips
298 CBugtraqRegexTestDlg dlg(this);
299 dlg.m_sBugtraqRegex2 = m_Logregex;
300 dlg.m_sBugtraqRegex2.Trim();
301 dlg.m_sBugtraqRegex2.Replace(_T("\r\n"), _T("\n"));
302 if (dlg.m_sBugtraqRegex2.Find('\n') >= 0)
304 dlg.m_sBugtraqRegex1 = dlg.m_sBugtraqRegex2.Mid(dlg.m_sBugtraqRegex2.Find('\n')).Trim();
305 dlg.m_sBugtraqRegex2 = dlg.m_sBugtraqRegex2.Left(dlg.m_sBugtraqRegex2.Find('\n')).Trim();
307 if (dlg.DoModal() == IDOK)
309 m_Logregex = dlg.m_sBugtraqRegex2 + _T("\n") + dlg.m_sBugtraqRegex1;
310 m_Logregex.Trim();
311 m_Logregex.Replace(_T("\n"), _T("\r\n"));
312 UpdateData(FALSE);