added new log filter (for subject)
[TortoiseGit.git] / src / TortoiseProc / SendMailDlg.cpp
blobff7e302fe197e27b78eac8e0b9ab145d4fe08aa7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 // SendMailDlg.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SendMailDlg.h"
25 #include "MessageBox.h"
26 #include "commonresource.h"
27 #include "AppUtils.h"
28 #include "PatchListCtrl.h"
29 #include "MailMsg.h"
30 // CSendMailDlg dialog
32 IMPLEMENT_DYNAMIC(CSendMailDlg, CResizableStandAloneDialog)
34 CSendMailDlg::CSendMailDlg(CWnd* pParent /*=NULL*/)
35 : CResizableStandAloneDialog(CSendMailDlg::IDD, pParent)
36 , m_To(_T(""))
37 , m_CC(_T(""))
38 , m_Subject(_T(""))
40 , m_regAttach(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Attach"),0)
41 , m_regCombine(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Combine"),0)
42 , m_regUseMAPI(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI"),0)
44 m_bAttachment = m_regAttach;
45 m_bCombine = m_regCombine;
46 m_bUseMAPI = m_regUseMAPI;
47 this->m_ctrlList.m_ContextMenuMask &=~ m_ctrlList.GetMenuMask(CPatchListCtrl::MENU_SENDMAIL);
50 CSendMailDlg::~CSendMailDlg()
54 void CSendMailDlg::DoDataExchange(CDataExchange* pDX)
56 CDialog::DoDataExchange(pDX);
57 DDX_Text(pDX, IDC_SENDMAIL_TO, m_To);
58 DDX_Text(pDX, IDC_SENDMAIL_CC, m_CC);
59 DDX_Check(pDX, IDC_SENDMAIL_ATTACHMENT, m_bAttachment);
60 DDX_Check(pDX, IDC_SENDMAIL_COMBINE, m_bCombine);
61 DDX_Check(pDX, IDC_SENDMAIL_MAPI, m_bUseMAPI);
62 DDX_Control(pDX, IDC_SENDMAIL_PATCHS, m_ctrlList);
63 DDX_Control(pDX,IDC_SENDMAIL_SETUP, this->m_SmtpSetup);
64 DDX_Control(pDX,IDC_SENDMAIL_TO,m_ctrlTO);
65 DDX_Control(pDX,IDC_SENDMAIL_CC,m_ctrlCC);
69 BEGIN_MESSAGE_MAP(CSendMailDlg, CResizableStandAloneDialog)
70 ON_BN_CLICKED(IDC_SENDMAIL_COMBINE, &CSendMailDlg::OnBnClickedSendmailCombine)
71 ON_BN_CLICKED(IDOK, &CSendMailDlg::OnBnClickedOk)
72 ON_NOTIFY(LVN_ITEMCHANGED, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnLvnItemchangedSendmailPatchs)
73 ON_NOTIFY(NM_DBLCLK, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnNMDblclkSendmailPatchs)
74 ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT, &CSendMailDlg::OnEnChangeSendmailSubject)
75 ON_BN_CLICKED(IDC_SENDMAIL_MAPI, &CSendMailDlg::OnBnClickedSendmailMapi)
76 END_MESSAGE_MAP()
78 // CSendMailDlg message handlers
80 BOOL CSendMailDlg::PreTranslateMessage(MSG* pMsg)
82 m_ToolTip.RelayEvent(pMsg);
84 return CDialog::PreTranslateMessage(pMsg);
87 BOOL CSendMailDlg::OnInitDialog()
89 CResizableStandAloneDialog::OnInitDialog();
90 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
92 AddAnchor(IDC_SENDMAIL_GROUP,TOP_LEFT,TOP_RIGHT);
93 AddAnchor(IDC_SENDMAIL_TO,TOP_LEFT,TOP_RIGHT);
94 AddAnchor(IDC_SENDMAIL_CC,TOP_LEFT,TOP_RIGHT);
95 AddAnchor(IDC_SENDMAIL_SUBJECT,TOP_LEFT,TOP_RIGHT);
96 AddAnchor(IDC_SENDMAIL_SETUP,TOP_RIGHT);
98 AddAnchor(IDC_SENDMAIL_PATCHS,TOP_LEFT,BOTTOM_RIGHT);
99 AddAnchor(IDOK,BOTTOM_RIGHT);
100 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
101 AddAnchor(IDHELP, BOTTOM_RIGHT);
103 this->AddOthersToAnchor();
104 EnableSaveRestore(_T("SendMailDlg"));
106 CString sWindowTitle;
107 GetWindowText(sWindowTitle);
108 CAppUtils::SetWindowTitle(m_hWnd, m_PathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
110 CString mailCient;
111 CMailMsg::DetectMailClient(mailCient);
112 if (mailCient.IsEmpty()) {
113 m_bUseMAPI = false;
114 GetDlgItem(IDC_SENDMAIL_MAPI)->EnableWindow(false);
115 GetDlgItem(IDC_SENDMAIL_MAPI)->SendMessage(BM_SETCHECK, BST_UNCHECKED);
118 m_ctrlCC.Init();
119 m_ctrlTO.Init();
121 m_ctrlCC.SetSeparator(_T(";"));
122 m_ctrlTO.SetSeparator(_T(";"));
124 m_AddressReg.SetMaxHistoryItems(0xFFFF);
126 m_AddressReg.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));
127 for(int i=0;i<m_AddressReg.GetCount();i++)
129 m_ctrlCC.AddSearchString(m_AddressReg.GetEntry(i));
130 m_ctrlTO.AddSearchString(m_AddressReg.GetEntry(i));
133 m_ctrlList.SetExtendedStyle( m_ctrlList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
135 for(int i=0;i<m_PathList.GetCount();i++)
137 m_ctrlList.InsertItem(i,m_PathList[i].GetWinPathString());
138 m_ctrlList.SetCheck(i,true);
141 // m_ctrlCC.AddSearchString(_T("Tortoisegit-dev@google.com"));
142 // m_ctrlTO.AddSearchString(_T("Tortoisegit-dev@google.com"));
143 this->UpdateData(FALSE);
144 OnBnClickedSendmailCombine();
146 //Create the ToolTip control
147 if( !m_ToolTip.Create(this))
149 TRACE0("Unable to create the ToolTip!");
151 else
153 m_ToolTip.SetMaxTipWidth(1024*8); // make multiline tooltips possible
154 m_ToolTip.AddTool(GetDlgItem(IDC_SENDMAIL_MAPI), _T("Be warned that email clients tend to automatic wrap lines.\r\nRecommendation: Use attachments."));
155 m_ToolTip.Activate(TRUE);
158 return TRUE;
160 void CSendMailDlg::OnBnClickedSendmailCombine()
162 this->UpdateData();
163 this->GetDlgItem(IDC_SENDMAIL_SUBJECT)->EnableWindow(this->m_bCombine);
164 if(m_bCombine)
165 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(this->m_Subject);
167 UpdateSubject();
170 void CSendMailDlg::OnBnClickedOk()
172 this->UpdateData();
174 if(this->m_To.IsEmpty() && this->m_CC.IsEmpty())
176 CMessageBox::Show(NULL,IDS_ERR_ADDRESS_NO_EMPTY,IDS_APPNAME,MB_OK|MB_ICONERROR);
177 return;
179 int start =0;
180 CString Address;
181 while(start>=0)
183 Address=this->m_CC.Tokenize(_T(";"),start);
184 m_AddressReg.AddEntry(Address);
185 m_AddressReg.Save();
187 start =0;
188 while(start>=0)
190 Address=this->m_To.Tokenize(_T(";"),start);
191 m_AddressReg.AddEntry(Address);
192 m_AddressReg.Save();
195 this->m_PathList.Clear();
196 for(int i=0;i<m_ctrlList.GetItemCount();i++)
198 CTGitPath path;
199 if(m_ctrlList.GetCheck(i))
201 path.SetFromWin(m_ctrlList.GetItemText(i,0));
202 this->m_PathList.AddPath(path);
206 m_regAttach=m_bAttachment;
207 m_regCombine=m_bCombine;
208 m_regUseMAPI=m_bUseMAPI;
210 OnOK();
213 void CSendMailDlg::UpdateSubject()
215 this->UpdateData();
217 if(!this->m_bCombine)
219 if(m_ctrlList.GetSelectedCount()==1)
221 POSITION pos=m_ctrlList.GetFirstSelectedItemPosition();
222 int index=m_ctrlList.GetNextSelectedItem(pos);
223 if(this->m_MapPatch.find(index) == m_MapPatch.end() )
225 CString pathfile=m_ctrlList.GetItemText(index,0);
226 m_MapPatch[index].Parser(pathfile);
228 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(m_MapPatch[index].m_Subject);
230 else
232 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(_T(""));
237 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)
239 UNREFERENCED_PARAMETER(pNMHDR);
240 UpdateSubject();
242 *pResult = 0;
245 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)
247 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
249 CString path=this->m_ctrlList.GetItemText(pNMItemActivate->iItem,0);
250 CTGitPath gitpath;
251 gitpath.SetFromWin(path);
253 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
255 *pResult = 0;
258 void CSendMailDlg::OnEnChangeSendmailSubject()
260 this->UpdateData();
261 if(this->m_bCombine)
262 GetDlgItem(IDC_SENDMAIL_SUBJECT)->GetWindowText(this->m_Subject);
265 void CSendMailDlg::OnBnClickedSendmailMapi()
267 this->UpdateData();