OSDN Git Service

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