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
23 #include "TortoiseProc.h"
24 #include "SendMailDlg.h"
25 #include "MessageBox.h"
26 #include "commonresource.h"
28 #include "PatchListCtrl.h"
30 // CSendMailDlg dialog
32 IMPLEMENT_DYNAMIC(CSendMailDlg
, CResizableStandAloneDialog
)
34 CSendMailDlg::CSendMailDlg(CWnd
* pParent
/*=NULL*/)
35 : CResizableStandAloneDialog(CSendMailDlg::IDD
, pParent
)
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
)
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();
91 AddAnchor(IDC_SENDMAIL_GROUP
,TOP_LEFT
,TOP_RIGHT
);
92 AddAnchor(IDC_SENDMAIL_TO
,TOP_LEFT
,TOP_RIGHT
);
93 AddAnchor(IDC_SENDMAIL_CC
,TOP_LEFT
,TOP_RIGHT
);
94 AddAnchor(IDC_SENDMAIL_SUBJECT
,TOP_LEFT
,TOP_RIGHT
);
95 AddAnchor(IDC_SENDMAIL_SETUP
,TOP_RIGHT
);
97 AddAnchor(IDC_SENDMAIL_PATCHS
,TOP_LEFT
,BOTTOM_RIGHT
);
98 AddAnchor(IDOK
,BOTTOM_RIGHT
);
99 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
100 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
102 this->AddOthersToAnchor();
103 EnableSaveRestore(_T("SendMailDlg"));
106 CMailMsg::DetectMailClient(mailCient
);
107 if (mailCient
.IsEmpty()) {
109 GetDlgItem(IDC_SENDMAIL_MAPI
)->EnableWindow(false);
110 GetDlgItem(IDC_SENDMAIL_MAPI
)->SendMessage(BM_SETCHECK
, BST_UNCHECKED
);
116 m_ctrlCC
.SetSeparator(_T(";"));
117 m_ctrlTO
.SetSeparator(_T(";"));
119 m_AddressReg
.SetMaxHistoryItems(0xFFFF);
121 m_AddressReg
.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));
122 for(int i
=0;i
<m_AddressReg
.GetCount();i
++)
124 m_ctrlCC
.AddSearchString(m_AddressReg
.GetEntry(i
));
125 m_ctrlTO
.AddSearchString(m_AddressReg
.GetEntry(i
));
128 m_ctrlList
.SetExtendedStyle( m_ctrlList
.GetExtendedStyle()| LVS_EX_CHECKBOXES
);
130 for(int i
=0;i
<m_PathList
.GetCount();i
++)
132 m_ctrlList
.InsertItem(i
,m_PathList
[i
].GetWinPathString());
133 m_ctrlList
.SetCheck(i
,true);
136 // m_ctrlCC.AddSearchString(_T("Tortoisegit-dev@google.com"));
137 // m_ctrlTO.AddSearchString(_T("Tortoisegit-dev@google.com"));
138 this->UpdateData(FALSE
);
139 OnBnClickedSendmailCombine();
141 //Create the ToolTip control
142 if( !m_ToolTip
.Create(this))
144 TRACE0("Unable to create the ToolTip!");
148 m_ToolTip
.SetMaxTipWidth(1024*8); // make multiline tooltips possible
149 m_ToolTip
.AddTool(GetDlgItem(IDC_SENDMAIL_MAPI
), _T("Be warned that email clients tend to automatic wrap lines.\r\nRecommendation: Use attachments."));
150 m_ToolTip
.Activate(TRUE
);
155 void CSendMailDlg::OnBnClickedSendmailCombine()
158 this->GetDlgItem(IDC_SENDMAIL_SUBJECT
)->EnableWindow(this->m_bCombine
);
160 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(this->m_Subject
);
165 void CSendMailDlg::OnBnClickedOk()
169 if(this->m_To
.IsEmpty() && this->m_CC
.IsEmpty())
171 CMessageBox::Show(NULL
,IDS_ERR_ADDRESS_NO_EMPTY
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
178 Address
=this->m_CC
.Tokenize(_T(";"),start
);
179 m_AddressReg
.AddEntry(Address
);
185 Address
=this->m_To
.Tokenize(_T(";"),start
);
186 m_AddressReg
.AddEntry(Address
);
190 this->m_PathList
.Clear();
191 for(int i
=0;i
<m_ctrlList
.GetItemCount();i
++)
194 if(m_ctrlList
.GetCheck(i
))
196 path
.SetFromWin(m_ctrlList
.GetItemText(i
,0));
197 this->m_PathList
.AddPath(path
);
201 m_regAttach
=m_bAttachment
;
202 m_regCombine
=m_bCombine
;
203 m_regUseMAPI
=m_bUseMAPI
;
208 void CSendMailDlg::UpdateSubject()
212 if(!this->m_bCombine
)
214 if(m_ctrlList
.GetSelectedCount()==1)
216 POSITION pos
=m_ctrlList
.GetFirstSelectedItemPosition();
217 int index
=m_ctrlList
.GetNextSelectedItem(pos
);
218 if(this->m_MapPatch
.find(index
) == m_MapPatch
.end() )
220 CString pathfile
=m_ctrlList
.GetItemText(index
,0);
221 m_MapPatch
[index
].Parser(pathfile
);
223 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(m_MapPatch
[index
].m_Subject
);
227 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(_T(""));
232 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR
*pNMHDR
, LRESULT
*pResult
)
234 UNREFERENCED_PARAMETER(pNMHDR
);
240 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR
*pNMHDR
, LRESULT
*pResult
)
242 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
244 CString path
=this->m_ctrlList
.GetItemText(pNMItemActivate
->iItem
,0);
246 gitpath
.SetFromWin(path
);
248 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
253 void CSendMailDlg::OnEnChangeSendmailSubject()
257 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->GetWindowText(this->m_Subject
);
260 void CSendMailDlg::OnBnClickedSendmailMapi()