OSDN Git Service

Complete Send mail coding and mail send have some problem.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SendMailDlg.cpp
1 // SendMailDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "SendMailDlg.h"\r
7 #include "MessageBox.h"\r
8 #include "commonresource.h"\r
9 #include "AppUtils.h"\r
10 \r
11 // CSendMailDlg dialog\r
12 \r
13 IMPLEMENT_DYNAMIC(CSendMailDlg, CResizableStandAloneDialog)\r
14 \r
15 CSendMailDlg::CSendMailDlg(CWnd* pParent /*=NULL*/)\r
16         : CResizableStandAloneDialog(CSendMailDlg::IDD, pParent)\r
17         , m_To(_T(""))\r
18         , m_CC(_T(""))\r
19         , m_Subject(_T(""))\r
20         , m_bAttachment(FALSE)\r
21         , m_bCombine(FALSE)\r
22 {\r
23 \r
24 }\r
25 \r
26 CSendMailDlg::~CSendMailDlg()\r
27 {\r
28 }\r
29 \r
30 void CSendMailDlg::DoDataExchange(CDataExchange* pDX)\r
31 {\r
32         CDialog::DoDataExchange(pDX);\r
33         DDX_Text(pDX, IDC_SENDMAIL_TO, m_To);\r
34         DDX_Text(pDX, IDC_SENDMAIL_CC, m_CC);\r
35         DDX_Check(pDX, IDC_SENDMAIL_ATTACHMENT, m_bAttachment);\r
36         DDX_Check(pDX, IDC_SENDMAIL_COMBINE, m_bCombine);\r
37         DDX_Control(pDX, IDC_SENDMAIL_PATCHS, m_ctrlList);\r
38         DDX_Control(pDX,IDC_SENDMAIL_SETUP, this->m_SmtpSetup);\r
39         DDX_Control(pDX,IDC_SENDMAIL_TO,m_ctrlTO);\r
40         DDX_Control(pDX,IDC_SENDMAIL_CC,m_ctrlCC);\r
41 }\r
42 \r
43 \r
44 BEGIN_MESSAGE_MAP(CSendMailDlg, CResizableStandAloneDialog)\r
45         ON_BN_CLICKED(IDC_SENDMAIL_COMBINE, &CSendMailDlg::OnBnClickedSendmailCombine)\r
46         ON_BN_CLICKED(IDOK, &CSendMailDlg::OnBnClickedOk)\r
47         ON_NOTIFY(LVN_ITEMCHANGED, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnLvnItemchangedSendmailPatchs)\r
48         ON_NOTIFY(NM_DBLCLK, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnNMDblclkSendmailPatchs)\r
49         ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT, &CSendMailDlg::OnEnChangeSendmailSubject)\r
50 END_MESSAGE_MAP()\r
51 \r
52 \r
53 // CSendMailDlg message handlers\r
54 \r
55 BOOL CSendMailDlg::OnInitDialog()\r
56 {\r
57         CResizableStandAloneDialog::OnInitDialog();\r
58 \r
59         AddAnchor(IDC_SENDMAIL_GROUP,TOP_LEFT,TOP_RIGHT);\r
60         AddAnchor(IDC_SENDMAIL_TO,TOP_LEFT,TOP_RIGHT);\r
61         AddAnchor(IDC_SENDMAIL_CC,TOP_LEFT,TOP_RIGHT);\r
62         AddAnchor(IDC_SENDMAIL_SUBJECT,TOP_LEFT,TOP_RIGHT);\r
63         AddAnchor(IDC_SENDMAIL_SETUP,TOP_RIGHT);\r
64 \r
65         AddAnchor(IDC_SENDMAIL_PATCHS,TOP_LEFT,BOTTOM_RIGHT);\r
66         AddAnchor(IDOK,BOTTOM_RIGHT);\r
67         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
68 \r
69         this->AddOthersToAnchor();\r
70         EnableSaveRestore(_T("SendMailDlg"));\r
71 \r
72         m_ctrlCC.Init();\r
73         m_ctrlTO.Init();\r
74 \r
75         m_ctrlCC.SetSeparator(_T(";"));\r
76         m_ctrlTO.SetSeparator(_T(";"));\r
77 \r
78         m_AddressReg.SetMaxHistoryItems(0xFFFF);\r
79 \r
80         m_AddressReg.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));\r
81         for(int i=0;i<m_AddressReg.GetCount();i++)\r
82         {\r
83                 m_ctrlCC.AddSearchString(m_AddressReg.GetEntry(i));\r
84                 m_ctrlTO.AddSearchString(m_AddressReg.GetEntry(i));\r
85         }\r
86 \r
87         m_ctrlList.SetExtendedStyle( m_ctrlList.GetExtendedStyle()| LVS_EX_CHECKBOXES );\r
88 \r
89         for(int i=0;i<m_PathList.GetCount();i++)\r
90         {\r
91                 m_ctrlList.InsertItem(i,m_PathList[i].GetWinPathString());\r
92                 m_ctrlList.SetCheck(i,true);\r
93         }\r
94         \r
95 //      m_ctrlCC.AddSearchString(_T("Tortoisegit-dev@google.com"));\r
96 //      m_ctrlTO.AddSearchString(_T("Tortoisegit-dev@google.com"));\r
97         this->UpdateData(FALSE);\r
98         OnBnClickedSendmailCombine();\r
99         return TRUE;\r
100 }\r
101 void CSendMailDlg::OnBnClickedSendmailCombine()\r
102 {\r
103         // TODO: Add your control notification handler code here\r
104         this->UpdateData();\r
105         this->GetDlgItem(IDC_SENDMAIL_SUBJECT)->EnableWindow(this->m_bCombine);\r
106         if(m_bCombine)\r
107                 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(this->m_Subject);\r
108 \r
109         UpdateSubject();\r
110 }\r
111 \r
112 void CSendMailDlg::OnBnClickedOk()\r
113 {\r
114         \r
115         this->UpdateData();\r
116 \r
117         if(this->m_To.IsEmpty() && this->m_CC.IsEmpty())\r
118         {\r
119                 CMessageBox::Show(NULL,IDS_ERR_ADDRESS_NO_EMPTY,IDS_APPNAME,MB_OK|MB_ICONERROR);\r
120                 return;\r
121         }\r
122         int start =0;\r
123         CString Address;\r
124         while(start>=0)\r
125         {\r
126                 Address=this->m_CC.Tokenize(_T(";"),start);\r
127                 m_AddressReg.AddEntry(Address);\r
128                 m_AddressReg.Save();\r
129         }\r
130         start =0;\r
131         while(start>=0)\r
132         {\r
133                 Address=this->m_To.Tokenize(_T(";"),start);\r
134                 m_AddressReg.AddEntry(Address);\r
135                 m_AddressReg.Save();\r
136         }       \r
137         \r
138         this->m_PathList.Clear();\r
139         for(int i=0;i<m_ctrlList.GetItemCount();i++)\r
140         {\r
141                 CTGitPath path;\r
142                 if(m_ctrlList.GetCheck(i))\r
143                 {\r
144                         path.SetFromWin(m_ctrlList.GetItemText(i,0));\r
145                         this->m_PathList.AddPath(path);\r
146                 }\r
147         }\r
148         OnOK();\r
149         // TODO: Add your control notification handler code here\r
150 }\r
151 \r
152 void CSendMailDlg::UpdateSubject()\r
153 {\r
154         this->UpdateData();\r
155 \r
156         if(!this->m_bCombine)\r
157         {\r
158                 if(m_ctrlList.GetSelectedCount()==1)\r
159                 {\r
160                         POSITION pos=m_ctrlList.GetFirstSelectedItemPosition();\r
161                         int index=m_ctrlList.GetNextSelectedItem(pos);\r
162                         if(this->m_MapPatch.find(index) == m_MapPatch.end() )\r
163                         {\r
164                                 m_MapPatch[index].Parser(m_ctrlList.GetItemText(index,0));\r
165                         }\r
166                         GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(m_MapPatch[index].m_Subject);\r
167                 }\r
168                 else\r
169                 {\r
170                         GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(_T(""));\r
171                 }\r
172         }\r
173 }\r
174 \r
175 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)\r
176 {\r
177         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
178         \r
179         UpdateSubject();\r
180         // TODO: Add your control notification handler code here\r
181         \r
182         *pResult = 0;\r
183 }\r
184 \r
185 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)\r
186 {\r
187         LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);\r
188         // TODO: Add your control notification handler code here\r
189         CString path=this->m_ctrlList.GetItemText(pNMItemActivate->iItem,0);\r
190         CTGitPath gitpath;\r
191         gitpath.SetFromWin(path);\r
192         \r
193         CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());\r
194 \r
195         *pResult = 0;\r
196 }\r
197 \r
198 void CSendMailDlg::OnEnChangeSendmailSubject()\r
199 {\r
200         // TODO:  If this is a RICHEDIT control, the control will not\r
201         // send this notification unless you override the CResizableStandAloneDialog::OnInitDialog()\r
202         // function and call CRichEditCtrl().SetEventMask()\r
203         // with the ENM_CHANGE flag ORed into the mask.\r
204 \r
205         // TODO:  Add your control notification handler code here\r
206         this->UpdateData();\r
207         if(this->m_bCombine)\r
208                 GetDlgItem(IDC_SENDMAIL_SUBJECT)->GetWindowText(this->m_Subject);\r
209 }\r